-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
220 lines (174 loc) · 8.14 KB
/
app.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import streamlit as st
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
st.set_option("deprecation.showPyplotGlobalUse", False)
# from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.neighbors import KNeighborsClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from sklearn import model_selection
# from sklearn.preprocessing import LabelEncoder
matplotlib.use("Agg")
from PIL import Image
# Set title
st.title("Machine Learning App")
image = Image.open("ml new.jpeg")
st.image(image, use_column_width=True)
def main():
activities = ["EDA", "Visualisation", "model", "About Vic3sax"]
option = st.sidebar.selectbox("Selection option:", activities)
# DEALING WITH THE EDA PART
if option == "EDA":
st.subheader("Exploratory Data Analysis")
image = Image.open("EDA.jpeg")
st.image(image, use_column_width=True)
data = st.file_uploader("Upload dataset:", type=["csv", "xlsx", "txt", "json"])
st.success("Data successfully loaded")
if data is not None:
df = pd.read_csv(data)
st.dataframe(df.head(50))
if st.checkbox("Display shape"):
st.write(df.shape)
if st.checkbox("Display columns"):
st.write(df.columns)
if st.checkbox("Select multiple columns"):
selected_columns = st.multiselect(
"Select preferred columns:", df.columns
)
df1 = df[selected_columns]
st.dataframe(df1)
if st.checkbox("Display summary"):
st.write(df1.describe().T)
if st.checkbox("Display Null Values"):
st.write(df.isnull().sum())
if st.checkbox("Display the data types"):
st.write(df.dtypes)
if st.checkbox("Display Correlation of data variuos columns"):
st.write(df.corr())
# DEALING WITH THE VISUALISATION PART
elif option == "Visualisation":
st.subheader("Data Visualisation")
image = Image.open("visualization.png")
st.image(image, use_column_width=True)
data = st.file_uploader("Upload dataset:", type=["csv", "xlsx", "txt", "json"])
st.success("Data successfully loaded")
if data is not None:
df = pd.read_csv(data)
st.dataframe(df.head(50))
if st.checkbox("Select Multiple columns to plot"):
selected_columns = st.multiselect(
"Select your preferred columns", df.columns
)
df1 = df[selected_columns]
st.dataframe(df1)
if st.checkbox("Display Heatmap"):
st.write(
sns.heatmap(
df1.corr(), vmax=1, square=True, annot=True, cmap="viridis"
)
)
st.pyplot()
if st.checkbox("Display Pairplot"):
st.write(sns.pairplot(df1, diag_kind="kde"))
st.pyplot()
if st.checkbox("Display Pie Chart"):
all_columns = df.columns.to_list()
pie_columns = st.selectbox("select column to display", all_columns)
pieChart = df[pie_columns].value_counts().plot.pie(autopct="%1.1f%%")
st.write(pieChart)
st.pyplot()
# DEALING WITH THE MODEL BUILDING PART
elif option == "model":
st.subheader("Model Building")
image = Image.open("model.webp")
st.image(image, use_column_width=True)
data = st.file_uploader("Upload dataset:", type=["csv", "xlsx", "txt", "json"])
st.success("Data successfully loaded")
if data is not None:
df = pd.read_csv(data)
st.dataframe(df.head(50))
if st.checkbox("Select Multiple columns"):
new_data = st.multiselect(
"Select your preferred columns. NB: Let your target variable be the last column to be selected",
df.columns,
)
df1 = df[new_data]
st.dataframe(df1)
# Dividing my data into X and y variables
X = df1.iloc[:, 0:-1]
y = df1.iloc[:, -1]
seed = st.sidebar.slider("Seed", 1, 200)
classifier_name = st.sidebar.selectbox(
"Select your preferred classifier:",
("KNN", "SVM", "LR", "naive_bayes", "decision tree"),
)
def add_parameter(name_of_clf):
params = dict()
if name_of_clf == "SVM":
C = st.sidebar.slider("C", 0.01, 15.0)
params["C"] = C
else:
name_of_clf == "KNN"
K = st.sidebar.slider("K", 1, 15)
params["K"] = K
return params
# calling the function
params = add_parameter(classifier_name)
# defing a function for our classifier
def get_classifier(name_of_clf, params):
clf = None
if name_of_clf == "SVM":
clf = SVC(C=params["C"])
elif name_of_clf == "KNN":
clf = KNeighborsClassifier(n_neighbors=params["K"])
elif name_of_clf == "LR":
clf = LogisticRegression()
elif name_of_clf == "naive_bayes":
clf = GaussianNB()
elif name_of_clf == "decision tree":
clf = DecisionTreeClassifier()
else:
st.warning("Select your choice of algorithm")
return clf
clf = get_classifier(classifier_name, params)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=seed
)
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)
st.write("Predictions:", y_pred)
accuracy = accuracy_score(y_test, y_pred)
st.write("Name of classifier:", classifier_name)
st.write("Accuracy", accuracy)
# DELING WITH THE ABOUT US PAGE
elif option == "About Vic3sax":
st.markdown("My name is `Victory Nnaji Ebubechukwu` also known as `vic3sax`")
st.markdown("🧑💻 I am a `Data Scientist`")
st.markdown(
"🏫 I am also a `Computer Engineering` Student at Enugu State University of Science and Technology"
)
st.markdown("🧑💻 I love using Software as a solution for every Problem")
st.markdown(
"📝 I have a strong foundation and interest in `Data Science` and `Artificial Intelligence`"
)
st.markdown(
"🧑🎓 I’m currently enhancing my knowledge on: `Full Stack Data Science`, `Machine Learning Engineering`, `Deep Learning`, `Computer Vision`, and `Natural Language Processing`"
)
st.markdown("🤓 Looking for `Internship` & `Junior Data Science Roles`")
st.markdown(
"This is an interactive web page for ML projects, feel free to use it. The analysis in here is to demonstrate how we can present our wok to our stakeholders in an interractive way by building a web app for our machine learning algorithms using different dataset."
)
st.balloons()
# ..............
st.markdown(
"[](https://twitter.com/SaxVictory) [](https://www.linkedin.com/in/victory-nnaji-8186231b7/) [](https://github.com/Vic3sax)"
)
if __name__ == "__main__":
main()