<jupyter_start><jupyter_text>Using kaggle IPL dataset , predicting the runs scored for the first innings of the match<jupyter_code># importing essential libraries

import pandas as pd
import numpy as np
import matplotlib.pyplot  as plt
import seaborn as sns
import datetime as dt

import warnings
warnings.filterwarnings('ignore')

%matplotlib inline
# reading the dataset

df = pd.read_csv('ipl.csv')
df.head()
# Checking dataset information

df.info()
df.describe()
# checking all the missing values

df.isnull().sum()
# converting the date column datatype as datetime

df['date'] = pd.to_datetime( df['date'] , format ="%Y-%m-%d" )
df['date']
# checking value count of each team

df['bat_team'].value_counts()
# visualising teams vs year

plt.figure(figsize= (10,6))
sns.boxplot(df['bat_team'] , df['date'].dt.year)
plt.xticks(rotation =90)
plt.show()
# Selecting all those teams that have played majority of the year

teams  = df['bat_team'].value_counts().index [:10]
teams
# Selecting the dataframe as per the required teams

df = df[(df['bat_team'].isin(teams) & df['bowl_team'].isin(teams))]
df['bat_team'].value_counts()
df.columns
# there are alot of columns which donot contribute that much
# dropping various columns

df.drop(['mid','batsman', 'bowler' ,'striker','non-striker'] ,1, inplace= True)

df.head()
# Selecting only games that were played for atleast 5 overs 

df = df[df['overs'] >= 5]
df.head()
df['venue'].value_counts()
# Creating dummies for bat_team , bowl_team & venue

dummy = pd.get_dummies(df[['bat_team','bowl_team', 'venue']] , drop_first=True)
df = pd.concat([df,dummy] , 1)
df.drop(['bat_team','bowl_team', 'venue'] , 1 , inplace = True)
df.head()
# Creating X_train & X_test

X_train = df[(df['date'].dt.year <=2016)]
X_test = df[(df['date'].dt.year > 2016)]

y_train  = df[(df['date'].dt.year <= 2016)]['total']
y_test  = df[(df['date'].dt.year >  2016)]['total']

X_train.shape ,X_test.shape , y_train.shape , y_test.shape
# Dropping date column from X_train & X_test

X_train.drop('date' ,1 ,inplace= True)
X_test.drop('date' ,1 ,inplace= True)
# Using RandomForestRegressor

from sklearn.ensemble import RandomForestRegressor

rf = RandomForestRegressor(max_depth=10 , n_estimators= 20 ,random_state=101)
rf.fit(X_train,y_train)
print('Training accuracy = {}'.format(round(rf.score(X_train,y_train),2)))
print('Test accuracy = {}'.format(round(rf.score(X_test,y_test),2)))
# Predicting on the test set 

y_test_pred = rf.predict(X_test)

sns.distplot(y_test - y_test_pred)
plt.ylim(0,4)
plt.xlim(-1,1)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15447154471544716, 'fraction_numerical': 0.01664730933023616, 'mean_word_length': 5.8, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '647847', 'license': 'MIT', 'n_tokens_mistral': 990, 'n_tokens_neox': 938, 'n_words': 236, 'path': 'IPL Score predictor .ipynb', 'repo_name': 'rahulh1998/IPL-', 'size': '2583'}