OLS Regression hands on code ...help

Executed this piece of code as suggested , but unable to complete the handson … any suggestion please?

from sklearn.datasets
import load_boston
import pandas as pd
boston = load_boston()
dataset = pd.DataFrame(data=boston.data, columns=boston.feature_names)
dataset[‘target’] = boston.target
print(dataset.head())

X = dataset[“RM”]
Y = dataset[“target”]

import statsmodels.api as sm
X= sm.add_constant(X)
statsModel =sm.OLS(Y,X)
fittedModel = statsModel.fit()

print (fittedModel.summary())

r_squared = fittedModel.rsquared
with open(“output.txt”, “w”) as text_file:
text_file.write(“rsquared= %f\n” % r_squared)

What exact issue are you having?

1 Like

Thank you for the response …I execute this code on Jupyter note … and return to Fresco play to validate … the code is not accepted

Jupyter note question is as below :-

So you’ve run this code, but you say you can’t “compete” it, and it “doesn’t work.” It’s not clear what that means. Do get any errors?

1 Like

Yes ,I have run the code I got the output as well printed on the text file I didn’t get any error message …but unable to complete the hands on … may be the handson questions is expecting something different … thats why I provide the link to the question as well … Will you be able to check and validate please?