<jupyter_start><jupyter_text><jupyter_code>#Runs Scored = index 7

import numpy as np
import matplotlib.pyplot as plt  # To visualize
import pandas as pd  # To read data
from sklearn.linear_model import LinearRegression
#Age vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
age_X = data.iloc[:, 4].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_age_vs_runs = LinearRegression()  # create object for the class
simple_age_vs_runs.fit(age_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_age_vs_runs.predict(age_X)  # make predictions

plt.scatter(age_X, runs_Y)
plt.plot(age_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_age_vs_runs.coef_)
print('y-axis intercept: ', simple_age_vs_runs.intercept_) 
age_predictions = simple_age_vs_runs.predict(age_X)
print(f"True output: {runs_Y_pred[4]}")
print(f"Predicted output: {age_predictions[4]}")
print(f"Prediction Error: {age_predictions[4]-runs_Y_pred[4]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
age_predicted = simple_age_vs_runs.predict(age_X)

# Score the prediction with mse and r2
age_mse = mean_squared_error(runs_Y, age_predicted)
age_r2 = r2_score(runs_Y, age_predicted)

print(f"Mean Squared Error (MSE): {age_mse}")
print(f"R-squared (R2 ): {age_r2}")

linear_regressor_age = simple_age_vs_runs.score(age_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_age}")

#Games Played vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
games_X = data.iloc[:, 5].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_games_vs_runs = LinearRegression()  # create object for the class
simple_games_vs_runs.fit(games_X, runs_Y)  # perform linear regression
games_Y_pred = simple_games_vs_runs.predict(games_X)  # make predictions

plt.scatter(games_X, runs_Y)
plt.plot(games_X, games_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_games_vs_runs.coef_)
print('y-axis intercept: ', simple_games_vs_runs.intercept_) 
games_predictions = simple_games_vs_runs.predict(age_X)
print(f"True output: {runs_Y_pred[5]}")
print(f"Predicted output: {games_predictions[5]}")
print(f"Prediction Error: {games_predictions[5]-runs_Y_pred[5]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
games_predicted = simple_games_vs_runs.predict(age_X)

# Score the prediction with mse and r2
games_mse = mean_squared_error(runs_Y, games_predicted)
games_r2 = r2_score(runs_Y, games_predicted)

print(f"Mean Squared Error (MSE): {games_mse}")
print(f"R-squared (R2 ): {games_r2}")

linear_regressor_games = simple_games_vs_runs.score(games_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_games}")

#At Bats vs Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
bats_X = data.iloc[:, 6].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_bats_vs_runs = LinearRegression()  # create object for the class
simple_bats_vs_runs.fit(bats_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_bats_vs_runs.predict(bats_X)  # make predictions

plt.scatter(bats_X, runs_Y)
plt.plot(bats_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_bats_vs_runs.coef_)
print('y-axis intercept: ', simple_bats_vs_runs.intercept_) 
bats_predictions = simple_bats_vs_runs.predict(age_X)
print(f"True output: {runs_Y_pred[6]}")
print(f"Predicted output: {bats_predictions[6]}")
print(f"Prediction Error: {bats_predictions[6]-runs_Y_pred[6]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
bats_predicted = simple_bats_vs_runs.predict(bats_X)

# Score the prediction with mse and r2
bats_mse = mean_squared_error(runs_Y, bats_predicted)
bats_r2 = r2_score(runs_Y, bats_predicted)

print(f"Mean Squared Error (MSE): {bats_mse}")
print(f"R-squared (R2 ): {bats_r2}")

linear_regressor_bats = simple_bats_vs_runs.score(games_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_bats}")

#Hitters vs Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
hit_X = data.iloc[:, 8].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_hit_vs_runs = LinearRegression()  # create object for the class
simple_hit_vs_runs.fit(hit_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_hit_vs_runs.predict(hit_X)  # make predictions
plt.scatter(hit_X, runs_Y)
plt.plot(hit_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_hit_vs_runs.coef_)
print('y-axis intercept: ', simple_hit_vs_runs.intercept_) 
hit_predictions = simple_hit_vs_runs.predict(hit_X)
print(f"True output: {runs_Y_pred[8]}")
print(f"Predicted output: {hit_predictions[8]}")
print(f"Prediction Error: {hit_predictions[8]-runs_Y_pred[8]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
hit_predicted = simple_hit_vs_runs.predict(hit_X)

# Score the prediction with mse and r2
hit_mse = mean_squared_error(runs_Y, hit_predicted)
hit_r2 = r2_score(runs_Y, hit_predicted)

print(f"Mean Squared Error (MSE): {hit_mse}")
print(f"R-squared (R2 ): {hit_r2}")

linear_regressor_hit = simple_hit_vs_runs.score(games_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_hit}")

#Double vs Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
double_X = data.iloc[:, 9].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_double_vs_runs = LinearRegression()  # create object for the class
simple_double_vs_runs.fit(double_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_double_vs_runs.predict(double_X)  # make predictions
plt.scatter(double_X, runs_Y)
plt.plot(double_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_double_vs_runs.coef_)
print('y-axis intercept: ', simple_double_vs_runs.intercept_) 
double_predictions = simple_double_vs_runs.predict(double_X)
print(f"True output: {runs_Y_pred[9]}")
print(f"Predicted output: {double_predictions[9]}")
print(f"Prediction Error: {double_predictions[9]-runs_Y_pred[9]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
double_predicted = simple_double_vs_runs.predict(double_X)

# Score the prediction with mse and r2
double_mse = mean_squared_error(runs_Y, double_predicted)
double_r2 = r2_score(runs_Y, double_predicted)

print(f"Mean Squared Error (MSE): {double_mse}")
print(f"R-squared (R2 ): {double_r2}")

linear_regressor_double = simple_double_vs_runs.score(double_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_double}")

#Triple vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
triple_X = data.iloc[:, 10].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_triple_vs_runs = LinearRegression()  # create object for the class
simple_triple_vs_runs.fit(triple_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_triple_vs_runs.predict(triple_X)  # make predictions
plt.scatter(triple_X, runs_Y)
plt.plot(triple_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_triple_vs_runs.coef_)
print('y-axis intercept: ', simple_triple_vs_runs.intercept_) 
triple_predictions = simple_triple_vs_runs.predict(double_X)
print(f"True output: {runs_Y_pred[10]}")
print(f"Predicted output: {triple_predictions[10]}")
print(f"Prediction Error: {triple_predictions[10]-runs_Y_pred[10]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
triple_predicted = simple_triple_vs_runs.predict(triple_X)

# Score the prediction with mse and r2
triple_mse = mean_squared_error(runs_Y, triple_predicted)
triple_r2 = r2_score(runs_Y, triple_predicted)

print(f"Mean Squared Error (MSE): {triple_mse}")
print(f"R-squared (R2 ): {triple_r2}")

linear_regressor_triple = simple_triple_vs_runs.score(triple_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_triple}")

#Home Runs vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
home_X = data.iloc[:, 11].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_home_vs_runs = LinearRegression()  # create object for the class
simple_home_vs_runs.fit(home_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_home_vs_runs.predict(home_X)  # make predictions
plt.scatter(home_X, runs_Y)
plt.plot(home_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_home_vs_runs.coef_)
print('y-axis intercept: ', simple_home_vs_runs.intercept_) 
home_predictions = simple_home_vs_runs.predict(home_X)
print(f"True output: {runs_Y_pred[11]}")
print(f"Predicted output: {home_predictions[11]}")
print(f"Prediction Error: {home_predictions[11]-runs_Y_pred[11]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
home_predicted = simple_home_vs_runs.predict(home_X)

# Score the prediction with mse and r2
home_mse = mean_squared_error(runs_Y, home_predicted)
home_r2 = r2_score(runs_Y, home_predicted)

print(f"Mean Squared Error (MSE): {home_mse}")
print(f"R-squared (R2 ): {home_r2}")

linear_regressor_home = simple_home_vs_runs.score(home_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_home}")

#Runs Batted In vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
rbi_X = data.iloc[:, 12].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_rbi_vs_runs = LinearRegression()  # create object for the class
simple_rbi_vs_runs.fit(rbi_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_rbi_vs_runs.predict(rbi_X)  # make predictions
plt.scatter(rbi_X, runs_Y)
plt.plot(rbi_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_rbi_vs_runs.coef_)
print('y-axis intercept: ', simple_rbi_vs_runs.intercept_) 
rbi_predictions = simple_rbi_vs_runs.predict(rbi_X)
print(f"True output: {runs_Y_pred[12]}")
print(f"Predicted output: {rbi_predictions[12]}")
print(f"Prediction Error: {rbi_predictions[12]-runs_Y_pred[12]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
rbi_predicted = simple_rbi_vs_runs.predict(rbi_X)

# Score the prediction with mse and r2
rbi_mse = mean_squared_error(runs_Y, rbi_predicted)
rbi_r2 = r2_score(runs_Y, rbi_predicted)

print(f"Mean Squared Error (MSE): {rbi_mse}")
print(f"R-squared (R2 ): {rbi_r2}")

linear_regressor_rbi = simple_rbi_vs_runs.score(rbi_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_rbi}")

#Stolen Base In vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
stolen_X = data.iloc[:, 12].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_stolen_vs_runs = LinearRegression()  # create object for the class
simple_stolen_vs_runs.fit(stolen_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_stolen_vs_runs.predict(stolen_X)  # make predictions
plt.scatter(stolen_X, runs_Y)
plt.plot(stolen_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_stolen_vs_runs.coef_)
print('y-axis intercept: ', simple_stolen_vs_runs.intercept_) 
stolen_predictions = simple_stolen_vs_runs.predict(stolen_X)
print(f"True output: {runs_Y_pred[13]}")
print(f"Predicted output: {stolen_predictions[13]}")
print(f"Prediction Error: {stolen_predictions[13]-runs_Y_pred[13]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
stolen_predicted = simple_stolen_vs_runs.predict(stolen_X)

# Score the prediction with mse and r2
stolen_mse = mean_squared_error(runs_Y, stolen_predicted)
stolen_r2 = r2_score(runs_Y, stolen_predicted)

print(f"Mean Squared Error (MSE): {stolen_mse}")
print(f"R-squared (R2 ): {stolen_r2}")

linear_regressor_stolen = simple_stolen_vs_runs.score(stolen_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_stolen}")

#Caught Stealing In vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
caught_X = data.iloc[:, 14].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_caught_vs_runs = LinearRegression()  # create object for the class
simple_caught_vs_runs.fit(caught_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_caught_vs_runs.predict(caught_X)  # make predictions
plt.scatter(caught_X, runs_Y)
plt.plot(caught_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_caught_vs_runs.coef_)
print('y-axis intercept: ', simple_caught_vs_runs.intercept_) 
caught_predictions = simple_caught_vs_runs.predict(caught_X)
print(f"True output: {runs_Y_pred[14]}")
print(f"Predicted output: {caught_predictions[14]}")
print(f"Prediction Error: {caught_predictions[14]-runs_Y_pred[14]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
caught_predicted = simple_caught_vs_runs.predict(caught_X)

# Score the prediction with mse and r2
caught_mse = mean_squared_error(runs_Y, caught_predicted)
caught_r2 = r2_score(runs_Y, caught_predicted)

print(f"Mean Squared Error (MSE): {caught_mse}")
print(f"R-squared (R2 ): {caught_r2}")

linear_regressor_caught = simple_caught_vs_runs.score(caught_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_caught}")

#Walks In vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
walk_X = data.iloc[:, 15].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_walk_vs_runs = LinearRegression()  # create object for the class
simple_walk_vs_runs.fit(walk_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_walk_vs_runs.predict(walk_X)  # make predictions
plt.scatter(walk_X, runs_Y)
plt.plot(walk_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_walk_vs_runs.coef_)
print('y-axis intercept: ', simple_walk_vs_runs.intercept_) 
walk_predictions = simple_walk_vs_runs.predict(walk_X)
print(f"True output: {runs_Y_pred[15]}")
print(f"Predicted output: {walk_predictions[15]}")
print(f"Prediction Error: {walk_predictions[15]-runs_Y_pred[15]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
walk_predicted = simple_walk_vs_runs.predict(walk_X)

# Score the prediction with mse and r2
walk_mse = mean_squared_error(runs_Y, walk_predicted)
walk_r2 = r2_score(runs_Y, walk_predicted)

print(f"Mean Squared Error (MSE): {walk_mse}")
print(f"R-squared (R2 ): {walk_r2}")

linear_regressor_walk = simple_walk_vs_runs.score(walk_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_walk}")

#Stike Out vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
strike_X = data.iloc[:, 16].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_strike_vs_runs = LinearRegression()  # create object for the class
simple_strike_vs_runs.fit(strike_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_strike_vs_runs.predict(strike_X)  # make predictions
plt.scatter(strike_X, runs_Y)
plt.plot(strike_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_strike_vs_runs.coef_)
print('y-axis intercept: ', simple_strike_vs_runs.intercept_) 
strike_predictions = simple_strike_vs_runs.predict(strike_X)
print(f"True output: {runs_Y_pred[16]}")
print(f"Predicted output: {strike_predictions[16]}")
print(f"Prediction Error: {strike_predictions[16]-runs_Y_pred[16]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
strike_predicted = simple_strike_vs_runs.predict(strike_X)

# Score the prediction with mse and r2
strike_mse = mean_squared_error(runs_Y, strike_predicted)
strike_r2 = r2_score(runs_Y, strike_predicted)

print(f"Mean Squared Error (MSE): {strike_mse}")
print(f"R-squared (R2 ): {strike_r2}")

linear_regressor_strike = simple_strike_vs_runs.score(strike_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_strike}")

#Sacrifice Bunt vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
bunt_X = data.iloc[:, 17].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_bunt_vs_runs = LinearRegression()  # create object for the class
simple_bunt_vs_runs.fit(bunt_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_bunt_vs_runs.predict(bunt_X)  # make predictions
plt.scatter(bunt_X, runs_Y)
plt.plot(bunt_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_bunt_vs_runs.coef_)
print('y-axis intercept: ', simple_bunt_vs_runs.intercept_) 
bunt_predictions = simple_bunt_vs_runs.predict(bunt_X)
print(f"True output: {runs_Y_pred[17]}")
print(f"Predicted output: {bunt_predictions[17]}")
print(f"Prediction Error: {bunt_predictions[17]-runs_Y_pred[17]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
bunt_predicted = simple_bunt_vs_runs.predict(bunt_X)

# Score the prediction with mse and r2
bunt_mse = mean_squared_error(runs_Y, bunt_predicted)
bunt_r2 = r2_score(runs_Y, bunt_predicted)

print(f"Mean Squared Error (MSE): {bunt_mse}")
print(f"R-squared (R2 ): {bunt_r2}")

linear_regressor_bunt = simple_bunt_vs_runs.score(bunt_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_bunt}")

#Sacrifice Fly vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
fly_X = data.iloc[:, 18].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_fly_vs_runs = LinearRegression()  # create object for the class
simple_fly_vs_runs.fit(fly_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_fly_vs_runs.predict(fly_X)  # make predictions
plt.scatter(fly_X, runs_Y)
plt.plot(fly_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_fly_vs_runs.coef_)
print('y-axis intercept: ', simple_fly_vs_runs.intercept_) 
fly_predictions = simple_fly_vs_runs.predict(fly_X)
print(f"True output: {runs_Y_pred[18]}")
print(f"Predicted output: {fly_predictions[18]}")
print(f"Prediction Error: {fly_predictions[18]-runs_Y_pred[18]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
fly_predicted = simple_fly_vs_runs.predict(fly_X)

# Score the prediction with mse and r2
fly_mse = mean_squared_error(runs_Y, fly_predicted)
fly_r2 = r2_score(runs_Y, fly_predicted)

print(f"Mean Squared Error (MSE): {fly_mse}")
print(f"R-squared (R2 ): {fly_r2}")

linear_regressor_fly = simple_fly_vs_runs.score(fly_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_fly}")

#Hit by Pitch vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
pitch_X = data.iloc[:, 19].values.reshape(-1, 1)  # values converts it into a numpy array
runs_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_pitch_vs_runs = LinearRegression()  # create object for the class
simple_pitch_vs_runs.fit(pitch_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_pitch_vs_runs.predict(pitch_X)  # make predictions
plt.scatter(pitch_X, runs_Y)
plt.plot(pitch_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_pitch_vs_runs.coef_)
print('y-axis intercept: ', simple_pitch_vs_runs.intercept_) 
pitch_predictions = simple_pitch_vs_runs.predict(fly_X)
print(f"True output: {runs_Y_pred[19]}")
print(f"Predicted output: {pitch_predictions[19]}")
print(f"Prediction Error: {pitch_predictions[19]-runs_Y_pred[19]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
pitch_predicted = simple_pitch_vs_runs.predict(pitch_X)

# Score the prediction with mse and r2
pitch_mse = mean_squared_error(runs_Y, pitch_predicted)
pitch_r2 = r2_score(runs_Y, pitch_predicted)

print(f"Mean Squared Error (MSE): {pitch_mse}")
print(f"R-squared (R2 ): {pitch_r2}")

linear_regressor_pitch = simple_pitch_vs_runs.score(pitch_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_pitch}")

#Batting Average vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
ba_X = data.iloc[:, 20].values.reshape(-1, 1)  # values converts it into a numpy array
ba_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_ba_vs_runs = LinearRegression()  # create object for the class
simple_ba_vs_runs.fit(ba_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_ba_vs_runs.predict(ba_X)  # make predictions
plt.scatter(ba_X, runs_Y)
plt.plot(ba_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_ba_vs_runs.coef_)
print('y-axis intercept: ', simple_ba_vs_runs.intercept_) 
ba_predictions = simple_ba_vs_runs.predict(ba_X)
print(f"True output: {runs_Y_pred[20]}")
print(f"Predicted output: {ba_predictions[20]}")
print(f"Prediction Error: {ba_predictions[20]-runs_Y_pred[20]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
ba_predicted = simple_ba_vs_runs.predict(ba_X)

# Score the prediction with mse and r2
ba_mse = mean_squared_error(runs_Y, ba_predicted)
ba_r2 = r2_score(runs_Y, ba_predicted)

print(f"Mean Squared Error (MSE): {ba_mse}")
print(f"R-squared (R2 ): {ba_r2}")

linear_regressor_ba = simple_ba_vs_runs.score(ba_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_ba}")

#On Base Percentage vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
obp_X = data.iloc[:, 21].values.reshape(-1, 1)  # values converts it into a numpy array
obp_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_obp_vs_runs = LinearRegression()  # create object for the class
simple_obp_vs_runs.fit(obp_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_obp_vs_runs.predict(obp_X)  # make predictions
plt.scatter(obp_X, runs_Y)
plt.plot(obp_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_obp_vs_runs.coef_)
print('y-axis intercept: ', simple_obp_vs_runs.intercept_) 
obp_predictions = simple_obp_vs_runs.predict(obp_X)
print(f"True output: {runs_Y_pred[21]}")
print(f"Predicted output: {obp_predictions[21]}")
print(f"Prediction Error: {obp_predictions[21]-runs_Y_pred[21]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
obp_predicted = simple_obp_vs_runs.predict(obp_X)

# Score the prediction with mse and r2
obp_mse = mean_squared_error(runs_Y, obp_predicted)
obp_r2 = r2_score(runs_Y, obp_predicted)

print(f"Mean Squared Error (MSE): {obp_mse}")
print(f"R-squared (R2 ): {obp_r2}")

linear_regressor_obp = simple_obp_vs_runs.score(obp_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_obp}")

#Slugging Percentage vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
slug_X = data.iloc[:, 22].values.reshape(-1, 1)  # values converts it into a numpy array
obp_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_slug_vs_runs = LinearRegression()  # create object for the class
simple_slug_vs_runs.fit(slug_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_slug_vs_runs.predict(slug_X)  # make predictions
plt.scatter(slug_X, runs_Y)
plt.plot(slug_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_slug_vs_runs.coef_)
print('y-axis intercept: ', simple_slug_vs_runs.intercept_) 
slug_predictions = simple_slug_vs_runs.predict(obp_X)
print(f"True output: {runs_Y_pred[22]}")
print(f"Predicted output: {slug_predictions[22]}")
print(f"Prediction Error: {slug_predictions[22]-runs_Y_pred[22]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
slug_predicted = simple_slug_vs_runs.predict(slug_X)

# Score the prediction with mse and r2
slug_mse = mean_squared_error(runs_Y, slug_predicted)
slug_r2 = r2_score(runs_Y, slug_predicted)

print(f"Mean Squared Error (MSE): {slug_mse}")
print(f"R-squared (R2 ): {slug_r2}")

linear_regressor_slug = simple_slug_vs_runs.score(slug_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_slug}")

#On Base Plus Slugging vs. Runs Scored

data = pd.read_csv('Qualified_Leaders_Batters.csv')  # load data set
ops_X = data.iloc[:, 23].values.reshape(-1, 1)  # values converts it into a numpy array
ops_Y = data.iloc[:, 7].values.reshape(-1, 1)  # -1 means that calculate the dimension of rows, but have 1 column
simple_ops_vs_runs = LinearRegression()  # create object for the class
simple_ops_vs_runs.fit(ops_X, runs_Y)  # perform linear regression
runs_Y_pred = simple_ops_vs_runs.predict(ops_X)  # make predictions
plt.scatter(ops_X, runs_Y)
plt.plot(ops_X, runs_Y_pred, color='red')
plt.show()
print('Weight coefficients: ', simple_ops_vs_runs.coef_)
print('y-axis intercept: ', simple_ops_vs_runs.intercept_) 
ops_predictions = simple_ops_vs_runs.predict(obp_X)
print(f"True output: {runs_Y_pred[23]}")
print(f"Predicted output: {ops_predictions[23]}")
print(f"Prediction Error: {ops_predictions[23]-runs_Y_pred[23]}")

from sklearn.metrics import mean_squared_error, r2_score

# Use our model to predict a value
ops_predicted = simple_ops_vs_runs.predict(ops_X)

# Score the prediction with mse and r2
ops_mse = mean_squared_error(runs_Y, ops_predicted)
ops_r2 = r2_score(runs_Y, ops_predicted)

print(f"Mean Squared Error (MSE): {ops_mse}")
print(f"R-squared (R2 ): {ops_r2}")

linear_regressor_ops = simple_ops_vs_runs.score(ops_X, runs_Y)
print(f"Linear Regressor Score (X, Y): {linear_regressor_ops}")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1150297835246259, 'fraction_numerical': 0.0150007264274299, 'mean_word_length': 6.925446171560162, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '67102', 'license': 'ADSL', 'n_tokens_mistral': 11077, 'n_tokens_neox': 10587, 'n_words': 2308, 'path': 'Simple_Linear_Regression_for_Qualified_Leaders_(2010_2019).ipynb', 'repo_name': 'ArunKara/Aliens-Are-Real-Website-using-Javascript', 'size': '27532'}