Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7 . 6 LAB: Performing logistic regression using LogisticRegression ( ) The nbaallelo _ log file contains data on 1 2 6 3 1 4

7.6 LAB: Performing logistic regression using LogisticRegression()
The nbaallelo_log file contains data on 126314 NBA games from 1947 to 2015. The dataset includes the features pts, elo_i,
win_equiv, and game_result. Using the csv file nbaallelo_log.csv and scikit-learn's LogisticRegression function,
construct a logistic regression model to classify whether a team will win or lose a game based on the team's elo_i score.
Hot encode the game_result variable as a numeric variable with 0 for L and 1 for W
Use the LogisticRegression function to construct a logistic regression model with game_result as the target and elo_i as
the predictor.
Predict the probability of a win from an elo_i score of 1310.
Predict whether a team with an elo_i score of 1310 will win.
Note: Use ravel () from numpy to flatten the second argument of LogisticRegression. fit () into a 1-D array.
Ex: If a elo_i score of 1410 is used instead of 1310, the output is:
A team with the given elo_i score has predicted probability:
0.593 losing
0.407 winning
and the overall prediction is 0
# Import the necessary Libraries
import pandas as pd
from sklearn.linear_model import LogisticRegression
import numpy as np
# Load nbaallelo_log.csv into a dataframe
NBA = pd.read_csv("nbaallelo_log.csv")
# Hot encode the game_result variable as a numeric variable with 0 for L and 1 for W
# Your code here
# Store relevant columns as variables
x= NBA[['elo_i']].values.reshape (-1,1)
'game_result']].values.reshape (-1,1).astype(int)
# Initialize and fit the logistic model using the LogisticRegression function
# Your code here
# Predict the probability that an elo_i score of 1310 is a win / loss
outcomeProb =# Your code here
# Predict whether an elo_i score of 1310 is a win (1) or loss (0)
outcomePred =# Your code here
print("A team with the given elo_i score has predicted probability:
", end="")
print('%.3f'% outcomeProb[0][1]+" winning")
print("and the overall prediction is",
outcomePred [0])
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

More Books

Students also viewed these Databases questions

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago