Please help with OLS regression task

Hi all ,

i am a new bee to python . I need help on OLS regression home work problem. I tried to complete this task by own but unfortunately it didn’t worked either. Appericiate 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
statsModel =sm.OLS(Y,X)
fittedModel = statsModel.fit()

Here i am getting an error as below -

NameError Traceback (most recent call last)
in
1 ###Start code here
----> 2 statsModel =sm.OLS(Y,X)
3 fittedModel = statsModel.fit()
4 ###End code(approx 2 lines)

NameError: name ‘Y’ is not defined

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