#πŸ”’ Simple Regression Model.

59 messages Β· Page 1 of 1 (latest)

fresh shadow
#

My professor basically told me to go F myself when I asked him for help with this assignment. I have to use screen shots. The output is not what is expected.

steady lagoonBOT
#

@fresh shadow

Python help channel opened

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.

fresh shadow
#

here's the instructions

#

here's the code I have

#

and here's what the expected outcome is.

#

Simple Linear Regression Model.

thin crown
#

What's your question tho?

fresh shadow
#

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?

thin crown
#

Paste text plz, too hard to review code from ss

fresh shadow
#

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.

thin crown
#

But glancing, you're not following instructions.

#

What is your X and y supposed to be, given first instructions

fresh shadow
#

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.

thin crown
#

What is 'y' supposed to be?

#

Use your words.

fresh shadow
#

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']
'''

thin crown
#

What is 'y' supposed to represent?

#

I'm giving you the hint/answer that there's a mistake related to how you use y.

fresh shadow
#

I dont know what you mean?

#

I'm lost.

thin crown
fresh shadow
#

I don't know to tell you the truth.

#

there's no csv file to download if there was this would be easier.

thin crown
#

Y is the difference between pts and opposing pts. That's what the instructions say.

fresh shadow
#

yes and I did that.

thin crown
#

Now, what 'y' are you passing to fit?

fresh shadow
#

hold on.

thin crown
fresh shadow
#

how?

#

wait hold on.

#

alright I'm on to something.

#

Now I just have to get X to fit.

thin crown
#

Good, because your X is also wrong

#

Again, read instructions and then look at what X you're passing to fit

fresh shadow
#

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

thin crown
#

Just remember, pebkac

fresh shadow
#

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.

steady lagoonBOT
#
Python help channel closed

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.