Diff of /Tabs/visualise.py [000000] .. [fd0c0d]

Switch to unified view

a b/Tabs/visualise.py
1
"""This modules contains data about visualisation page"""
2
3
# Import necessary modules
4
import warnings
5
import matplotlib.pyplot as plt
6
import seaborn as sns
7
from sklearn.metrics import plot_confusion_matrix
8
from sklearn import tree
9
import streamlit as st
10
11
12
# Import necessary functions from web_functions
13
from web_functions import train_model
14
15
def app(df, X, y):
16
    """This function create the visualisation page"""
17
    
18
    # Remove the warnings
19
    warnings.filterwarnings('ignore')
20
    st.set_option('deprecation.showPyplotGlobalUse', False)
21
22
    # Set the page title
23
    st.title("Visualise the Parkinson's Prediction")
24
25
    # Create a checkbox to show correlation heatmap
26
    if st.checkbox("Show the correlation heatmap"):
27
        st.subheader("Correlation Heatmap")
28
29
        fig = plt.figure(figsize = (10, 6))
30
        ax = sns.heatmap(df.iloc[:, 1:].corr(), annot = True)   # Creating an object of seaborn axis and storing it in 'ax' variable
31
        bottom, top = ax.get_ylim()                             # Getting the top and bottom margin limits.
32
        ax.set_ylim(bottom + 0.5, top - 0.5)                    # Increasing the bottom and decreasing the top margins respectively.
33
        st.pyplot(fig)
34
35
    if st.checkbox("Show Scatter Plot"):
36
        
37
        figure, axis = plt.subplots(2, 2,figsize=(15,10))
38
39
        sns.scatterplot(ax=axis[0,0],data=df,x='AVFF',y='MAVFF',hue='status')
40
        axis[0, 0].set_title("Oversampling Minority Scatter")
41
  
42
        sns.countplot(ax=axis[0, 1],x="status", data=df)
43
        axis[0, 1].set_title("Oversampling Minority Count")
44
  
45
        sns.scatterplot(ax=axis[1, 0],data=df,x='AVFF',y='MAVFF',hue='status')
46
        axis[1, 0].set_title("Undersampling Majority Scatter")
47
  
48
        sns.countplot(ax=axis[1, 1],x="status", data=df)
49
        axis[1, 1].set_title("Undersampling Majority Count")
50
        st.pyplot()
51
52
    if st.checkbox("Display Boxplot"):
53
        fig, ax = plt.subplots(figsize=(15,5))
54
        df.boxplot(['AVFF', 'MAVFF', 'MIVFF','HNR'],ax=ax)
55
        st.pyplot()
56
57
    if st.checkbox("Show Sample Results"):
58
        safe = (df['status'] == 0).sum()
59
        prone = (df['status'] == 1).sum()
60
        data = [safe,prone]
61
        labels = ['Safe', 'Prone']
62
        colors = sns.color_palette('pastel')[0:7]
63
        plt.pie(data, labels = labels, colors = colors, autopct='%.0f%%')
64
        st.pyplot()
65
66
    
67
68
    if st.checkbox("Plot confusion matrix"):
69
        model, score = train_model(X, y)
70
        plt.figure(figsize = (10, 6))
71
        plot_confusion_matrix(model, X, y, values_format='d')
72
        st.pyplot()
73
74
    if st.checkbox("Plot Decision Tree"):
75
        model, score = train_model(X, y)
76
        # Export decision tree in dot format and store in 'dot_data' variable.
77
        dot_data = tree.export_graphviz(
78
            decision_tree=model, max_depth=3, out_file=None, filled=True, rounded=True,
79
            feature_names=X.columns, class_names=['0', '1']
80
        )
81
        # Plot the decision tree using the 'graphviz_chart' function of the 'streamlit' module.
82
        st.graphviz_chart(dot_data)
83