Python Forum
Can you help me with this code please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can you help me with this code please
#1
# Import statements 
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split 
from sklearn.metrics import r2_score
import pandas as pd

# Read the data.
data = pd.read_csv('data.csv')
# Assign the features to the variable X, and the labels to the variable Y. 
X = data['YearsExperience']
Y = data['Salary']


X_train,X_test,Y_train,Y_test = train_test_split(X,Y, test_size=0.33)

model = LinearRegression()

# TODO: Fit the model.
model.fit(X_train,Y_train)
# TODO: Make predictions. Store them in the variable y_pred.
y_pred = model.predict(X_test)


# TODO: Calculate the accuracy and assign it to the variable acc.
r2_score = r2_score(Y_test,y_pred)


print(r2_score)
Reply
#2
Are there error messages (if so, post complete and without modification)
Also, please provide some sample data.
Please be a little more specific as to what is wrong.
Reply
#3
(Jul-04-2022, 08:55 AM)Larz60+ Wrote: Are there error messages (if so, post complete and without modification)
Also, please provide some sample data.
Please be a little more specific as to what is wrong.
[/quote]
umm all I can do is give you the csv file and and the PDF file so maybe you can help
[/quote]



.csv   data.csv (Size: 454 bytes / Downloads: 84)
.pdf   1.-Linear-Regression-Assignment (wecompress.com).pdf (Size: 54.21 KB / Downloads: 134)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020