-
Notifications
You must be signed in to change notification settings - Fork 0
/
all-rounder.py
36 lines (25 loc) · 989 Bytes
/
all-rounder.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('Allrounder.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([' Sr.No.','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('Result',axis=1)
y=df['Result']
from sklearn.ensemble import RandomForestClassifier
rfmodel=RandomForestClassifier()
#Fitting model with training data
rfmodel.fit(X, y)
# Saving model to disk
pickle.dump(rfmodel, open('allrounder_model.pkl','wb'))
# Loading model to compare the results
model = pickle.load(open('allrounder_model.pkl','rb'))