forked from SHUBHAM-max449/Machine_Learning_Automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutomated_ML_App.py
635 lines (601 loc) · 39.1 KB
/
Automated_ML_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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
from collections import defaultdict
from sklearn.linear_model import LogisticRegression
from sklearn.neighbors import KNeighborsClassifier
from sklearn import svm
from sklearn.tree import DecisionTreeClassifier,DecisionTreeRegressor
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import RandomForestClassifier,RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score, ConfusionMatrixDisplay, confusion_matrix
import pandas as pd
import numpy as np
import streamlit as st
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder,StandardScaler,MinMaxScaler
from PIL import Image
st.set_option('deprecation.showPyplotGlobalUse', False)
def main():
image = Image.open(
"business-manufacturing-process-automation-smart-industry-innovation-modern-technology-concept-143567093.jpg")
st.set_page_config(
page_title="Automated-ML-Model",
page_icon=image,
layout="wide",
)
st.markdown("<h1 style='text-align: center;font-family:georgia; color:#C3447A;'>Semi Automation Model</h1>",
unsafe_allow_html=True)
st.markdown(
"<h3 style='text-align: center;font-family:georgia; color:#000000;'>You're either the one that creats the automation or you're getting automated</h3>",
unsafe_allow_html=True)
choice = st.sidebar.radio('what you want to do',("Data info","Data Cleaning, Visualization and Machine Learning","About"))
st.sidebar.write("** Please upload valid data set **")
dataset = st.sidebar.file_uploader("Upload file here", type=['csv', 'txt', 'xls'])
if choice=="Data info":
if dataset is not None:
data = pd.read_csv(dataset, delimiter=',')
st.image(image)
st.write("Here is the complete information about the data")
st.subheader(" **Data column names**")
column_names=data.columns
for i in column_names:
st.write("*","*** ",i," ***")
st.write("---")
st.subheader(" **Data shape**")
values=data.shape
st.write("#### No of rows = ",values[0])
st.write("#### No of columns = ", values[1])
st.write("---")
st.subheader(" **Data head**")
st.table(data.head())
st.write("---")
st.subheader(" **Data info**")
st.write(data.info())
st.write("---")
st.subheader(" **Data describe**")
st.table(data.describe())
elif choice=="Data Cleaning, Visualization and Machine Learning":
if dataset is not None:
data = pd.read_csv(dataset, delimiter=',')
st.markdown("<h3 style='text-align: center;font-family:georgia;font-size:32px;color: #1e90ff;'>Data Cleaning</h3>", unsafe_allow_html=True)
st.write("**Data Before Clening**")
st.table(data.head())
st.write("**Null values in the data**")
null_val=data.isnull().sum()
null_val=null_val.reset_index()
null_val=null_val.rename(columns={'index':"Col_names",0:"Sum_of_Null_values"})
st.table(null_val)
plt.figure(figsize=(5,5))
st.write(sns.heatmap(data.isnull(),yticklabels=False,cbar=False,cmap='plasma'))
st.pyplot()
count = 0
var=0
total_col=0
min_val=int((data.shape[0])/2)
cleaned_data=data.copy()
for i in data.columns:
if null_val[null_val['Col_names'] == i]['Sum_of_Null_values'][count] > min_val:
cleaned_data=data.drop(labels=[i], axis=1)
var=var+1
else:
if total_col==len(data.columns) and var==0:
cleaned_data = data.copy()
total_col=total_col+1
count = count+1
# st.table(cleaned_data.head())
if var==data.shape[1]:
st.write("Can't proceed furture as it's all columns are containing more than 50% null values")
else:
if var > 0:
st.write("After Droping the columns which has more than 50% **NULL** values")
st.table(cleaned_data.head())
else:
st.write("Since NULL Values are Less than 50% We are not dropping any column")
st.write("** Want to see Unique values of a column: **")
yes=st.selectbox("",cleaned_data.columns)
if yes is not None:
st.write(cleaned_data[yes].unique())
st.write("**Select the column names which are of no use**")
Col_names_which_has_to_be_dropped = st.multiselect(" ", data.columns)
waste_columns = []
for i in range(0, len(Col_names_which_has_to_be_dropped)):
drop_name = Col_names_which_has_to_be_dropped[i]
waste_columns.append(drop_name)
cleaned_data = cleaned_data.drop(labels=waste_columns, axis=1)
st.table(cleaned_data.head())
cleaned_data_for_visualization=pd.DataFrame()
cleaned_data_for_visualization=cleaned_data
columns_with_null_values = []
count=0
for i in null_val['Col_names']:
if null_val[null_val['Col_names'] == i]['Sum_of_Null_values'][count] > 0 and null_val[null_val['Col_names'] == i]['Sum_of_Null_values'][count] < min_val :
columns_with_null_values.append(i)
count = count + 1
if len(columns_with_null_values)!=0:
st.write("**Do you want to drop all null values?**")
choice = st.radio('', ("Yes", "No"))
j = 0
if choice=="No":
a=0
b=600
for i in range(0,len(columns_with_null_values)):
st.write(" **Select the name of null values containing column name :** ")
null_colum_name=st.selectbox("",columns_with_null_values,key=a)
a=a+1
if len(cleaned_data[null_colum_name].unique()) > 10 :
st.subheader(" ** How you want to handle NUll values for that particular Column: **")
method_of_treating_null_value = st.selectbox("",['Mean of Values','Median of Values', 'Most Occuring element','Maximum val in column', 'Minimum val in column'],key=b)
b=b+1
if method_of_treating_null_value=='Mean of Values':
cleaned_data[null_colum_name]=cleaned_data[null_colum_name].replace(np.NAN,cleaned_data[null_colum_name].mean())
elif method_of_treating_null_value=='Median of Values':
cleaned_data[null_colum_name].fillna(cleaned_data[null_colum_name].median(), inplace=True)
elif method_of_treating_null_value=='Most Occuring element':
cleaned_data[null_colum_name].fillna(cleaned_data[null_colum_name].mode()[0], inplace=True)
elif method_of_treating_null_value=='Maximum val in column':
cleaned_data[null_colum_name].fillna(cleaned_data[null_colum_name].max(), inplace=True)
elif method_of_treating_null_value == 'Minimum val in column':
cleaned_data[null_colum_name].fillna(cleaned_data[null_colum_name].min(), inplace=True)
else:
st.subheader(" ** As this column is Categorical We can only replace with most occuring element: **")
cleaned_data[null_colum_name].fillna(cleaned_data[null_colum_name].mode()[0], inplace=True)
else:
cleaned_data.dropna(inplace=True)
null_val = cleaned_data.isnull().sum()
null_val = null_val.reset_index()
null_val = null_val.rename(columns={'index': "Col_names", 0: "Sum_of_Null_values"})
st.table(null_val)
values =cleaned_data.shape
st.write("#### No of rows = ", values[0])
st.write("#### No of columns = ", values[1])
lst = []
names = cleaned_data.columns
st.write("**Select target column name for Applying ML model**")
target = st.selectbox("", names,key="target")
st.write("Target:", "**", target, "**")
col_names = []
for i in cleaned_data.columns:
if i != target:
col_names.append(i)
for i in col_names:
if len(data[i].unique()) < ((data.shape[0])/100):
lst.append(i)
st.write("**There are** ", len(lst), " **Categorical column in the dataset **")
for i in lst:
st.write("*", i)
st.write("**Select encoding technique:**")
encoding_choice = st.radio("",('Label Encoding', 'One hot encoding', "Not Required"))
st.write("Converting Categorical columns into numerical by using",encoding_choice)
cat_clm_names = lst
if len(lst)>0:
if encoding_choice == 'Label Encoding':
d = defaultdict(LabelEncoder)
cleaned_data[cat_clm_names] = cleaned_data[cat_clm_names].apply(lambda x: d[x.name].fit_transform(x))
elif encoding_choice == 'One hot encoding':
cleaned_data = pd.get_dummies(cleaned_data, columns=cat_clm_names)
elif encoding_choice == 'Not Required':
pass
else:
st.write("** As there are no categorical columns in the feature columns Please select Not required as a option in encoding technique**")
st.table(cleaned_data.head())
st.write("**Data for Visualization:**")
st.table(cleaned_data_for_visualization.head())
if st.checkbox("Correlation"):
st.write(sns.heatmap(cleaned_data_for_visualization.corr(),annot=True))
st.pyplot()
st.write(sns.pairplot(cleaned_data_for_visualization))
st.pyplot()
if st.checkbox("Bar grapgh"):
x_axis = st.selectbox("Select x axis:", cleaned_data_for_visualization.columns)
x_axis = cleaned_data_for_visualization[x_axis]
y_axis = st.selectbox("Select y axis:", cleaned_data_for_visualization.columns)
y_axis = cleaned_data_for_visualization[y_axis]
st.write(sns.barplot(x_axis, y_axis))
st.pyplot()
plt.xticks(rotation=90)
plt.legend()
plt.grid()
if st.checkbox("COUNT PLOT"):
c = st.selectbox("Select axis:", cleaned_data_for_visualization.columns)
c_main = cleaned_data_for_visualization[c]
st.write(sns.countplot(c_main))
st.pyplot()
plt.grid()
plt.xticks(rotation=90)
plt.legend()
if st.checkbox("PIE CHART"):
col = st.selectbox("Select 1 column", cleaned_data_for_visualization.columns)
pie = cleaned_data_for_visualization[col].value_counts().plot.pie(autopct="%1.1f%%")
st.write(pie)
st.pyplot()
st.write("-----")
st.markdown(
"<h3 style='text-align: center;font-family:georgia;font-size:32px;color:#8000ff;'>Machine Learning-Model</h3>",
unsafe_allow_html=True)
st.write("** Do you want to Apply Machine Learning**")
tell=st.radio("",("Yes","No"),key=25)
ml_type=""
if len(cleaned_data[target].unique())<10:
ml_type="Classification"
else:
ml_type="Regression"
if tell=="Yes":
st.write("** After doing Train-Test-Split we have **")
X = cleaned_data.drop(labels=target, axis=1)
y = cleaned_data[target]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
values1 = X_train.shape
values2 = X_test.shape
values3 = y_train.shape
values4 = y_test.shape
st.write(" Shape of X_train = ", values1)
st.write(" Shape of X_test = ", values2)
st.write(" Shape of y_train = ", values3)
st.write(" Shape of y_test = ", values4)
st.write("")
st.write("** Do you want to apply Scaling to the data: **")
ss = st.radio("", ("Yes", "No"),key="SS")
if ss == "Yes":
st.write("** Select which standard scaling you want to use: **")
ss_tech = st.radio("", ("Standard Scalar", "Min Max Scalar"),key="SS_tech")
if ss_tech == "Standard Scalar":
meth = StandardScaler()
X_train=meth.fit_transform(X_train)
X_test=meth.transform(X_test)
st.write("** Data After Standard Scaling**")
st.write(X_train[0:5])
st.write("* According to the target Column which you have selected earlier we found that it's a ","**",ml_type,"**"," problem ")
if ml_type=="Classification":
if len(cleaned_data[target].unique())==2:
st.write("**Select the classification Algorithm:**")
ml_class_algorithm=st.selectbox("",("Logistic Regression","k-Nearest Neighbors","Decision Trees","Support Vector Machine","Naive Bayes","Random Forest Classifier"))
else:
st.write("**Select the classification Algorithm:**")
ml_class_algorithm=st.selectbox("", ("Naive Bayes", "k-Nearest Neighbors", "Decision Trees", "Support Vector Machine","Random Forest Classifier"))
model=''
algorithm=''
if ml_class_algorithm=="Logistic Regression":
model=LogisticRegression()
algorithm="Logistic Regression"
model.fit(X_train,y_train)
predictions=model.predict(X_test)
if ml_class_algorithm=="k-Nearest Neighbors":
algorithm = "KNN"
model=KNeighborsClassifier()
model.fit(X_train,y_train)
predictions=model.predict(X_test)
if ml_class_algorithm=="Decision Trees":
algorithm = "DTC"
model=DecisionTreeClassifier()
model.fit(X_train,y_train)
predictions=model.predict(X_test)
if ml_class_algorithm=="Support Vector Machine":
algorithm = "SVM"
model=svm.SVC(kernel='linear')
model.fit(X_train,y_train)
predictions=model.predict(X_test)
if ml_class_algorithm=="Naive Bayes":
algorithm = "Naive Bayes"
model=GaussianNB()
model.fit(X_train,y_train)
predictions=model.predict(X_test)
if ml_class_algorithm=="Random Forest Classifier":
algorithm = "RFC"
model=RandomForestClassifier()
model.fit(X_train,y_train)
predictions=model.predict(X_test)
st.write("**",algorithm,"**"," algoritm score is","**",model.score(X_test,y_test),"**")
st.write("")
st.markdown(
"<h3 style='text-align: center;font-family:georgia;font-size:32px;color:#000000;'>Confusion Matrix</h3>",
unsafe_allow_html=True)
cm = confusion_matrix(y_test, predictions, labels=model.classes_)
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=model.classes_)
disp.plot()
st.pyplot()
elif ml_type=="Regression":
st.write("** After doing Train-Test-Split we have **")
X = cleaned_data.drop(labels=target, axis=1)
y = cleaned_data[target]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,
random_state=42)
X_train_for, X_test_for, y_train_for, y_test_for = train_test_split(X.to_numpy(),
y.to_numpy(),
test_size=0.33,
random_state=42)
values1 = X_train.shape
values2 = X_test.shape
values3 = y_train.shape
values4 = y_test.shape
st.write(" Shape of X_train = ", values1)
st.write(" Shape of X_test = ", values2)
st.write(" Shape of y_train = ", values3)
st.write(" Shape of y_test = ", values4)
st.write("")
st.write(
"* According to the target Column which you have selected earlier we found that it's a ",
"**", ml_type, "**", " problem")
st.write("**Select the classification Algorithm:**")
ml_class_algorithm = st.selectbox("", (
"Linear Regression", "Support Vector Regression", "Random Forest Regressor",
"Decision Tree Regressor"))
model = ''
algorithm = ''
predictions = 0
if ml_class_algorithm == "Linear Regression":
model = LinearRegression()
algorithm = "Linear Regression"
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Support Vector Regression":
algorithm = "SVR"
model = svm.SVR()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Decision Tree Regressor":
algorithm = "DTR"
model = DecisionTreeRegressor()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Random Forest Regressor":
algorithm = "RFR"
model = RandomForestRegressor()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
st.write("**", algorithm, "**", " algoritm Root mean squared error is", "**",
np.sqrt(mean_squared_error(y_test, predictions)), "**")
st.write("**", algorithm, "**", " algoritm R2 score", "**",
r2_score(y_test, predictions), "**")
plt.scatter(predictions, y_test, color="violet")
plt.title("Predictions vs True Values ")
plt.show()
st.pyplot()
elif ss_tech=="Min Max Scalar":
meth = MinMaxScaler()
X_train = meth.fit_transform(X_train)
X_test = meth.transform(X_test)
st.write("** Data After Min Max Scaling **")
st.write(X_train[0:5])
st.write(
"* According to the target Column which you have selected earlier we found that it's a ",
"**", ml_type, "**", " problem ")
if ml_type == "Classification":
if len(cleaned_data[target].unique()) == 2:
st.write("**Select the classification Algorithm:**")
ml_class_algorithm = st.selectbox("", (
"Logistic Regression", "k-Nearest Neighbors", "Decision Trees",
"Support Vector Machine", "Naive Bayes", "Random Forest Classifier"))
else:
st.write("**Select the classification Algorithm:**")
ml_class_algorithm = st.selectbox("", (
"Naive Bayes", "k-Nearest Neighbors", "Decision Trees", "Support Vector Machine",
"Random Forest Classifier"))
model = ''
algorithm = ''
if ml_class_algorithm == "Logistic Regression":
model = LogisticRegression()
algorithm = "Logistic Regression"
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "k-Nearest Neighbors":
algorithm = "KNN"
model = KNeighborsClassifier()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Decision Trees":
algorithm = "DTC"
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Support Vector Machine":
algorithm = "SVM"
model = svm.SVC(kernel='linear')
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Naive Bayes":
algorithm = "Naive Bayes"
model = GaussianNB()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Random Forest Classifier":
algorithm = "RFC"
model = RandomForestClassifier()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
st.write("**", algorithm, "**", " algoritm score is", "**", model.score(X_test, y_test),
"**")
st.write("")
st.markdown(
"<h3 style='text-align: center;font-family:georgia;font-size:32px;color:#000000;'>Confusion Matrix</h3>",
unsafe_allow_html=True)
cm = confusion_matrix(y_test, predictions, labels=model.classes_)
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=model.classes_)
disp.plot()
st.pyplot()
elif ml_type=="Regression":
st.write("** After doing Train-Test-Split we have **")
X = cleaned_data.drop(labels=target, axis=1)
y = cleaned_data[target]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,
random_state=42)
X_train_for, X_test_for, y_train_for, y_test_for = train_test_split(X.to_numpy(),
y.to_numpy(),
test_size=0.33,
random_state=42)
values1 = X_train.shape
values2 = X_test.shape
values3 = y_train.shape
values4 = y_test.shape
st.write(" Shape of X_train = ", values1)
st.write(" Shape of X_test = ", values2)
st.write(" Shape of y_train = ", values3)
st.write(" Shape of y_test = ", values4)
st.write("")
st.write(
"* According to the target Column which you have selected earlier we found that it's a ",
"**", ml_type, "**", " problem")
st.write("**Select the classification Algorithm:**")
ml_class_algorithm = st.selectbox("", (
"Linear Regression", "Support Vector Regression", "Random Forest Regressor",
"Decision Tree Regressor"))
model = ''
algorithm = ''
predictions = 0
if ml_class_algorithm == "Linear Regression":
model = LinearRegression()
algorithm = "Linear Regression"
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Support Vector Regression":
algorithm = "SVR"
model = svm.SVR()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Decision Tree Regressor":
algorithm = "DTR"
model = DecisionTreeRegressor()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Random Forest Regressor":
algorithm = "RFR"
model = RandomForestRegressor()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
st.write("**", algorithm, "**", " algoritm Root mean squared error is", "**",
np.sqrt(mean_squared_error(y_test, predictions)), "**")
st.write("**", algorithm, "**", " algoritm R2 score", "**",
r2_score(y_test, predictions), "**")
plt.scatter(predictions, y_test, color="blue")
plt.title("Predictions vs True Values ")
plt.show()
st.pyplot()
elif ss=="No":
st.write(
"* According to the target Column which you have selected earlier we found that it's a ",
"**", ml_type, "**", " problem ")
if ml_type == "Classification":
if len(cleaned_data[target].unique()) == 2:
st.write("**Select the classification Algorithm:**")
ml_class_algorithm = st.selectbox("", (
"Logistic Regression", "k-Nearest Neighbors", "Decision Trees",
"Support Vector Machine", "Naive Bayes", "Random Forest Classifier"))
else:
st.write("**Select the classification Algorithm:**")
ml_class_algorithm = st.selectbox("", (
"Naive Bayes", "k-Nearest Neighbors", "Decision Trees", "Support Vector Machine",
"Random Forest Classifier"))
model = ''
algorithm = ''
if ml_class_algorithm == "Logistic Regression":
model = LogisticRegression()
algorithm = "Logistic Regression"
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "k-Nearest Neighbors":
algorithm = "KNN"
model = KNeighborsClassifier()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Decision Trees":
algorithm = "DTC"
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Support Vector Machine":
algorithm = "SVM"
model = svm.SVC(kernel='linear')
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Naive Bayes":
algorithm = "Naive Bayes"
model = GaussianNB()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Random Forest Classifier":
algorithm = "RFC"
model = RandomForestClassifier()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
st.write("**", algorithm, "**", " algoritm score is", "**", model.score(X_test, y_test),
"**")
st.write("")
st.markdown(
"<h3 style='text-align: center;font-family:georgia;font-size:32px;color:#000000;'>Confusion Matrix</h3>",
unsafe_allow_html=True)
cm = confusion_matrix(y_test, predictions, labels=model.classes_)
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=model.classes_)
disp.plot()
st.pyplot()
elif ml_type=="Regression":
st.write("** After doing Train-Test-Split we have **")
X = cleaned_data.drop(labels=target, axis=1)
y = cleaned_data[target]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,
random_state=42)
X_train_for, X_test_for, y_train_for, y_test_for = train_test_split(X.to_numpy(),
y.to_numpy(),
test_size=0.33,
random_state=42)
values1 = X_train.shape
values2 = X_test.shape
values3 = y_train.shape
values4 = y_test.shape
st.write(" Shape of X_train = ", values1)
st.write(" Shape of X_test = ", values2)
st.write(" Shape of y_train = ", values3)
st.write(" Shape of y_test = ", values4)
st.write("")
st.write(
"* According to the target Column which you have selected earlier we found that it's a ",
"**", ml_type, "**", " problem")
st.write("**Select the classification Algorithm:**")
ml_class_algorithm = st.selectbox("", (
"Linear Regression", "Support Vector Regression", "Random Forest Regressor",
"Decision Tree Regressor"))
model = ''
algorithm = ''
predictions = 0
if ml_class_algorithm == "Linear Regression":
model = LinearRegression()
algorithm = "Linear Regression"
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Support Vector Regression":
algorithm = "SVR"
model = svm.SVR()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Decision Tree Regressor":
algorithm = "DTR"
model = DecisionTreeRegressor()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
if ml_class_algorithm == "Random Forest Regressor":
algorithm = "RFR"
model = RandomForestRegressor()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
st.write("**", algorithm, "**", " algoritm Root mean squared error is", "**",
np.sqrt(mean_squared_error(y_test, predictions)), "**")
st.write("**", algorithm, "**", " algoritm R2 score", "**",
r2_score(y_test, predictions), "**")
plt.scatter(predictions, y_test, color="yellow")
plt.title("Predictions vs True Values ")
plt.show()
st.pyplot()
# st.write("Plot Predicted values ** v/s ** Actual values")
# st.write(sns.lmplot(x=predictions,y=y_test,data=cleaned_data,palette='red'))
# st.pyplot()
elif choice=="About":
st.subheader("--About Me--")
st.write(''' ''')
st.write(''' ***Built by Shubham Chitaguppe*** ''')
st.write(''' ***Insta*** : https://www.instagram.com/shubham_s_c/''')
st.write(''' ***Linkedin*** : https://www.linkedin.com/in/shubham-chitaguppe-2449821a9/''')
st.write(''' ***Github*** : https://github.com/SHUBHAM-max449''')
st.markdown(
"<h3 style='text-align: center;font-family:sans-serif;font-size:60px;color:#000000;'>Thank you</h3>",
unsafe_allow_html=True)
if __name__=="__main__":
main()