Python programming blog

Sunday, April 18, 2021

Cricket scores prediction using linear regression

 
Step1: Importing the Libraries
 
import numpy as np
import pandas as pd 
 
Numpy is for performing numerical calculations.
 
Pandas is for reading CSV files. 
 
 

 
 
Step 2: Reading the CSV files 
 
data = pd.read_csv('Sample scores.csv')
 
 
Step 3: Linear regression using SKLEARN 
 
from sklearn.linear_model import LinearRegression
 
 
Step 4: Data-Visualization 
 

import plotly.express as px
fig = px.scatter(data,x='Overs', y='Scores')
fig.show()

 
 
 
Step 5: Creating dataframes
 
linear_reg = LinearRegression()
x = data.Overs.values.reshape(-1,1)
y = data.Scores.values.reshape(-1,1)
 
 
 
Step 6 : Applying formula on dataframes
 
linear_reg.fit(x,y) 


Step 7: Prediction of 20th over

next_salary = linear_reg.predict([[19]])
print(int(next_salary))
 
Output: 8 runs will be 20th over score.
 
 
Thanks for reading this article💗

 
 
 


 

2 comments: