<jupyter_start><jupyter_text>Importing Dependencies<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
import sklearn
from datetime import datetime
import pickle
df = pd.read_csv('ipl.csv')
df.head()<jupyter_output><empty_output><jupyter_text>Data Cleaning<jupyter_code>columns_remove=['mid','venue','batsman','bowler','striker','non-striker']
df.drop(labels=columns_remove, axis=1, inplace=True)
df.info()
df.head()
df['bat_team'].unique()
#Keeping only consistent team
consistent_teams = ['Kolkata Knight Riders','Chennai Super Kings','Rajasthan Royals',
                    'Mumbai Indians','Kings XI Punjab','Royal Challengers Bangalore',
                    'Delhi Ddfaredevils','Sunrisers Hyderabad']
df = df[(df['bat_team'].isin(consistent_teams)) & (df['bowl_team'].isin(consistent_teams))]
df.shape
#Removing thw first 5 overs data from every match
df = df[df['overs']>=5.0]
df.head()
df.corr()
print(df['bat_team'].unique())
print(df['bowl_team'].unique())
# Converting the column 'date' from string into datetime object
df['date'] = df['date'].apply(lambda x: datetime.strptime(x, '%Y-%m-%d'))<jupyter_output><empty_output><jupyter_text>Data preprocessing<jupyter_code>#converting categorical features into oneHotencoding Method
df = pd.get_dummies(data=df,columns=['bat_team','bowl_team'])
df.head()
df.columns
# Rearranging the columns
df = df[['date', 'bat_team_Chennai Super Kings', 'bat_team_Delhi Daredevils', 'bat_team_Kings XI Punjab',
              'bat_team_Kolkata Knight Riders', 'bat_team_Mumbai Indians', 'bat_team_Rajasthan Royals',
              'bat_team_Royal Challengers Bangalore', 'bat_team_Sunrisers Hyderabad',
              'bowl_team_Chennai Super Kings', 'bowl_team_Delhi Daredevils', 'bowl_team_Kings XI Punjab',
              'bowl_team_Kolkata Knight Riders', 'bowl_team_Mumbai Indians', 'bowl_team_Rajasthan Royals',
              'bowl_team_Royal Challengers Bangalore', 'bowl_team_Sunrisers Hyderabad',
              'overs', 'runs', 'wickets', 'runs_last_5', 'wickets_last_5', 'total']]
df.head()
# Splitting the data into train and test set
x_train = df.drop(labels='total', axis=1)[df['date'].dt.year <=2016]
x_test = df.drop(labels='total', axis=1)[df['date'].dt.year >=2017]
y_train = df[df['date'].dt.year <=2016]['total'].values
y_test = df[df['date'].dt.year >=2017]['total'].values
#removing the 'Date' column
x_train.drop(labels='date',axis = 1,inplace=True)
x_test.drop(labels='date',axis = 1,inplace=True)<jupyter_output><empty_output><jupyter_text>Model Implementation  Linear Regression Model<jupyter_code>from sklearn.linear_model import LinearRegression
lr = LinearRegression()
lr.fit(x_train,y_train)
prediction = lr.predict(x_test)
prediction
from sklearn import metrics

print('mse:', metrics.mean_squared_error(y_test,prediction))
print('rmse:', np.sqrt(metrics.mean_squared_error(y_test,prediction)))
sns.distplot(y_test-prediction)<jupyter_output><empty_output><jupyter_text>Decision Tree<jupyter_code>from sklearn.tree import DecisionTreeRegressor
decision_regressor = DecisionTreeRegressor()
decision_regressor.fit(x_train,y_train)
y_pred_dt = decision_regressor.predict(x_test)
print('mse:', metrics.mean_squared_error(y_test,y_pred_dt))
print('rmse:', np.sqrt(metrics.mean_squared_error(y_test,y_pred_dt)))
sns.distplot(y_test-y_pred_dt)<jupyter_output><empty_output><jupyter_text>Creating a pickle file for the Model<jupyter_code>filename = 'first-innings-score-model.pkl'
pickle.dump(lr, open(filename, 'wb'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13950892857142858, 'fraction_numerical': 0.007254464285714286, 'mean_word_length': 7.222477064220183, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 28, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '72017', 'license': 'MIT', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1254, 'n_words': 228, 'path': 'First Innings Score Prediction.ipynb', 'repo_name': 'rohitpathak18/IPL-first-Innings-Score-prediction', 'size': '3584'}