#π Simple Regression Model.
59 messages Β· Page 1 of 1 (latest)
@fresh shadow
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
here's the instructions
here's the code I have
and here's what the expected outcome is.
Simple Linear Regression Model.
What's your question tho?
I keep getting a different outcome then what is expected. Look at the screen shots.
My question is what and where exactly am I doing wrong?
Paste text plz, too hard to review code from ss
okay .
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
# Read in nbaallelo_slr.csv
nba = pd.read_csv('nbaallelo_slr.csv')
# Create a new column in the data frame that is the difference between pts and opp_pts
nba['y'] = nba['pts'] - nba ['opp_pts']
# Store relevant columns as variables
X = nba[['pts']].values.reshape(-1,1)
y = nba[['opp_pts']].values.reshape(-1,1)
# Initialize the linear regression model
SLRModel = LinearRegression()
# Fit the model on X and y
SLRModel.fit(X, y)
# Print the intercept
intercept = SLRModel.intercept_
print('The intercept of the linear regression line is ', end="")
print('%.3f' % intercept[0] + ". ")
# Print the slope
slope = SLRModel.coef_
print('The slope of the linear regression line is ', end="")
print('%.3f' % slope[0][0] + ". ")
# Compute the proportion of variation explained by the linear regression using the LinearRegression object's score method
score = SLRModel.score(X, y)
print('The proportion of variation explained by the linear regression model is ', end="")
print('%.3f' % score + ". ")
there.
But glancing, you're not following instructions.
What is your X and y supposed to be, given first instructions
okay exactly where and how?
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.
these are the instructions. Their also in the screen shot.
you mean this?
Create a new column in the data frame that is the difference between pts and opp_pts
nba['y'] = nba['pts'] - nba ['opp_pts']
-_-
'''py # Create a new column in the data frame that is the difference between pts and opp_pts
nba['y'] = nba['pts'] - nba ['opp_pts']
'''
What is 'y' supposed to represent?
I'm giving you the hint/answer that there's a mistake related to how you use y.
In your words, what is y supposed to be?
I don't know to tell you the truth.
there's no csv file to download if there was this would be easier.
Y is the difference between pts and opposing pts. That's what the instructions say.
yes and I did that.
Now, what 'y' are you passing to fit?
hold on.
But... you never use the new y column you created.
how?
wait hold on.
alright I'm on to something.
Now I just have to get X to fit.
Good, because your X is also wrong
Again, read instructions and then look at what X you're passing to fit
wow. I'm dumber than I thought. XD
okay so X can't be 'pts'.
so X must be either elo_i or elo_n
try them both i guess.
alright I got it finally.
thank you.
nothing is ever simple in python. XD
Just remember, pebkac
that's how you know you work with computers. the constant tic tak of the keyboard, and the frustration to pull out your hair. Which sucks for me since I have short hair.
PEBKAC is an acronym for "Problem Exists Between Keyboard and Chair"
story of my god d*mn life.
always the simple mistakes.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.