Karan1908/Weather-Type-Classification
0
1'''2Author : Karan Chauhan3github : @Karan-Chauhan194Email : kc879022@gmail.com5Organization : L.J University6'''7 8import pandas as pd9import numpy as np10from build_features import *11from sklearn.model_selection import train_test_split12from sklearn.ensemble import RandomForestClassifier,BaggingClassifier13from sklearn.linear_model import LogisticRegression14from sklearn.metrics import classification_report,accuracy_score15from sklearn.pipeline import Pipeline16from sklearn.tree import DecisionTreeClassifier17from sklearn.svm import SVC18import streamlit as st19 20 21 22 23class ModelTrain :24 def __init__(self) :25 pass26 27 28 29 def train_model(self) :30 31 data = Featureengineering()32 df,preprocessor = data.get_clean_data()33 X = df.drop(columns=['WeatherType','Location'])34 y = df.iloc[:,-1]35 # X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=42)36 37 model_pipeline = Pipeline(steps=[38 ('preprocessor',preprocessor)39 ])40 model_pipeline.fit(X,y)41 transform_data = model_pipeline.named_steps['preprocessor'].transform(X)42 options = ['Random Forest Classifier','Decision Tree','Logistic Regression','SVM']43 selected_option = st.sidebar.selectbox("Select Algorithm ",options)44 45 Selected_Algorithm = object46 47 if selected_option == 'Random Forest Classifier' :48 Selected_Algorithm = RandomForestClassifier(max_features=0.2, max_samples=0.5, n_estimators=120)49 Selected_Algorithm.fit(transform_data,y)50 elif selected_option == 'Decision Tree' :51 Selected_Algorithm = DecisionTreeClassifier(max_depth=4,max_leaf_nodes=5,min_samples_split=50)52 Selected_Algorithm.fit(transform_data,y)53 elif selected_option == 'Logistic Regression' :54 Selected_Algorithm = LogisticRegression()55 Selected_Algorithm.fit(transform_data,y)56 else :57 Selected_Algorithm = SVC()58 Selected_Algorithm.fit(transform_data,y)59 60 return Selected_Algorithm,model_pipeline61 