Rupesh386 commited on
Commit
e9f3adc
·
verified ·
1 Parent(s): 7f6dfcb

Update train.py

Browse files
Files changed (1) hide show
  1. train.py +81 -0
train.py CHANGED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+ author : Rupesh Garsondiya
3
+ github : @Rupeshgarsondiya
4
+ Organization : L.J University
5
+ '''
6
+
7
+
8
+
9
+
10
+
11
+ import pandas as pd
12
+ import streamlit as st
13
+ import numpy as np
14
+ from features.build_features import *
15
+ from sklearn.model_selection import train_test_split
16
+ from sklearn.linear_model import LogisticRegression
17
+ from sklearn.ensemble import RandomForestClassifier
18
+ from sklearn.tree import DecisionTreeClassifier
19
+ from sklearn.neighbors import KNeighborsClassifier
20
+ from sklearn.svm import SVC
21
+ from sklearn.metrics import accuracy_score
22
+
23
+
24
+
25
+ class Model_Train:
26
+ def __init__(self) -> None:
27
+ pass
28
+
29
+ '''load_data() fuction use for to get the clean data or feature transformed data '''
30
+ def load_data(self):
31
+ pass
32
+
33
+
34
+ def train_model(self):
35
+ st.markdown(
36
+ """
37
+ <style>
38
+ body {
39
+ background-color: lightblue;
40
+ }
41
+ </style>
42
+ """,
43
+ unsafe_allow_html=True
44
+ )
45
+ fe = FeatureEngineering()
46
+ x_train,x_test,y_train,y_test,pipeline = fe.get_clean_data()
47
+
48
+
49
+ # Define the options for the dropdown menu
50
+ options = ['Logistic Regreesion', 'Random Forest Classifier', 'Decision Tree', 'SVM','KNeighborsClassifier']
51
+ # Create the dropdown menu
52
+ with st.container():
53
+ st.markdown('<div class="dropdown-left">', unsafe_allow_html=True)
54
+ selected_option = st.sidebar.selectbox('Select Algoritham :', options)
55
+ st.markdown('</div>', unsafe_allow_html=True)
56
+
57
+ S_algo = object
58
+ if selected_option== 'Logistic Regreesion':
59
+ S_algo = LogisticRegression()
60
+ S_algo.fit(x_train,y_train)
61
+ ypred = S_algo.predict(x_test)
62
+ elif selected_option=='Random Forest Classifier':
63
+ S_algo = RandomForestClassifier(n_estimators=200,n_jobs=-1,verbose=True,max_depth=2)
64
+ S_algo.fit(x_train,y_train)
65
+ ypred1 = S_algo.predict(x_test)
66
+ elif selected_option=='Decision Tree':
67
+ S_algo = DecisionTreeClassifier(max_depth=4,max_leaf_nodes=5,min_samples_split=50)
68
+ S_algo.fit(x_train,y_train)
69
+ ypred2 = S_algo.predict(x_test)
70
+ elif selected_option =='SVM':
71
+ S_algo = SVC()
72
+ S_algo.fit(x_train,y_train)
73
+ ypred3 = S_algo.predict(x_test)
74
+ elif selected_option=='KNeighborsClassifier':
75
+ S_algo = KNeighborsClassifier()
76
+ S_algo.fit(x_train,y_train)
77
+ ypred4 = S_algo.predict(x_test)
78
+ else:
79
+ pass
80
+
81
+ return S_algo,pipeline