Help on OLS regression home work problem

I need help on OLS regression home work problem. I tried to complete this task by own but unfortunately it didn’t worked either. Appericaie your help.

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())

Assign the values of column “RM”(average number of rooms per dwelling) to variable X
similerly assign the values of ‘target’(housing price) column to variable Y

###Start code here
X =
Y =
###End code(approx 2 lines)

initialise the OLS model by passing target(Y) and attribute(X).Assign the model to variable ‘statsModel’
fit the model and assign it to variable ‘fittedModel, make sure you add constant term to input X’
sample code for initialization: sm.OLS(target, attribute)

###Start code here

###End code(approx 2 lines)

print the summary of fittedModel using the summary() function

###Start code here

###End code(approx 1 line)

from the summary report note down the R-squared value and assign it to variable ‘r_squared’ in the below cell

###Start code here
r_squared =
###End code(approx 1 line)
with open(“output.txt”, “w”) as text_file:
text_file.write(“rsquared= %f\n” % r_squared)

1 Like