-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
33 lines (25 loc) · 1002 Bytes
/
model.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
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
from sklearn.pipeline import Pipeline
from sklearn.metrics import accuracy_score
from sklearn.ensemble import RandomForestClassifier
import pickle
df = pd.read_csv('C:\\Users\\saurav\\Dropbox\\PC\\Desktop\\IPL_WIN_PREDICTION\\dataset.csv')
x = df.iloc[:, :-1]
y = df.iloc[:,-1]
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.25,random_state=100)
trf = ColumnTransformer([
('trf',OneHotEncoder(sparse_output=False,drop='first',handle_unknown='ignore'),['batting_team','bowling_team','city'])
],
remainder='passthrough')
ra_pipe = Pipeline([
('step1',trf),
('step2',RandomForestClassifier())
])
ra_pipe.fit(x_train,y_train)
ra_y_pred = ra_pipe.predict(x_test)
pickle.dump(ra_pipe,open('ra_pipe.pkl','wb'))
print(accuracy_score(y_test,ra_y_pred))