Question: 7 . 5 LAB: Creating simple linear regression models The nbaallelo _ slr dataset contains information on 1 2 6 3 1 5 NBA games

7.5 LAB: Creating simple linear regression models
The nbaallelo_slr dataset contains information on 126315 NBA games between 1947 and 2015. The columns report the points made
by one team, the Elo rating of that team coming into the game, the Elo rating of the team after the game, and the points made by the
opposing team. The Elo score measures the relative skill of teams in a league.
Load the dataset into a data frame.
Create a new column y in the data frame that is the difference between the points made by the two teams.
Use sklearn's LinearRegression () function to perform a simple linear regression on the y and elo_i columns.
Compute the proportion of variation explained by the linear regression using the LinearRegression object's score method.
Ex: If the Elo rating of the team after the game, elon, is used instead of eloi, the output is:
The intercept of the linear regression line is -59.135.
The slope of the linear regression line is 0.040.
The proportion of variation explained by the linear regression model is 0.111.
525076.2609636.q3zqy7
LAB
ACTIVITY
7.5.1: LAB: Creating simple linear regression models
main.py
Load default template...
# Import the necessary modules
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
# Read in nbaallelo_slr.csv
nba=# Your code here
# Create a new column in the data frame that is the difference between pts and opp_pts
nba['y']= #Your code here
# Store relevant columns as variables
x=# Your code here
y=# Your code here
# Initialize the Linear regression model
SLRModel =# Your code here
# Fit the model on x and y
# Your code here
# Print the intercept
intercept =# Your code here
print ('The intercept of the linear regression line is ', end="")
# Print the slope
slope = # Your code here
print ("The slope of the linear regression line is ", end="")
# Compute the proportion of variation explained by the linear regression using the LinearRegression object's score me
score = # Your code here
print ('The proportion of variation explained by the linear regression model is ', end="")
print('%.3f'% score +".")]
 7.5 LAB: Creating simple linear regression models The nbaallelo_slr dataset contains

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!