[fd0c0d]: / Tabs / visualise.py

Download this file

84 lines (62 with data), 3.1 kB

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