-
Notifications
You must be signed in to change notification settings - Fork 0
/
bowler.py
36 lines (26 loc) · 1000 Bytes
/
bowler.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
# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import pickle
df = pd.read_csv('bowl.csv')
df.dropna(inplace=True)
#Converting words to integer values
ground=pd.get_dummies(df['Ground'])
pitch=pd.get_dummies(df['Pitch'])
opponent=pd.get_dummies(df['Opponent'])
weather=pd.get_dummies(df['Weather'])
homeaway=pd.get_dummies(df['Home/Away'])
df.drop(['Home/Away','Name','Ground','Pitch','Home Strike Rate','Away Strike Rate','Home Average','Away Average','Opponent','Weather'],axis=1,inplace=True)
df=pd.concat([df,ground,pitch,opponent,weather,homeaway],axis=1)
X=df.drop('Wickets',axis=1)
y=df['Wickets']
from sklearn.ensemble import RandomForestClassifier
rfmodel=RandomForestClassifier()
#Fitting model with trainig data
rfmodel.fit(X, y)
# Saving model to disk
pickle.dump(rfmodel, open('bowler_model.pkl','wb'))
# Loading model to compare the results
model = pickle.load(open('bowler_model.pkl','rb'))
#print(model.predict([[2, 9, 6]]))