Regression Anallysis Hands0n 1
Regression Anallysis Hands0n 1
In this exercise , you will try out simple linaer regression using stats model that
you have learnt in the course. We have created this Python Notebook with all the
necessary things needed for completing this exercise.
To run the code in each cell click on the cell and press shift + enter
Run the below cell to import the data and view first five rows of dataset
From the above output you can see the various attributes of the dataset.
The 'target' column has the dependent values(housing prices) and rest of the colums
are the independent values that influence the target values
Lets find the relation between 'housing price' and 'average number of rooms per
dwelling' using stats model
Assign the values of column "RM"(average number of rooms per dwelling) to variable
X
Similarly assign the values of 'target'(housing price) column to variable Y
sample code: values = data_frame['attribute_name']
###Start code here
X = dataset['RM']
Y = dataset['target']
###End code(approx 2 lines)
Import package
import statsmodels.api as sm
###Start code here
import statsmodels.api as sm
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'
Sample code for initialization: sm.OLS(target, attribute)
###Start code here
X = sm.add_constant(X)
statsModel = sm.OLS(Y,X)
fittedModel = statsModel.fit()
###End code(approx 2 lines)
Print Summary
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly
specified.
Extract r_squared value
From the summary report note down the R-squared value and assign it to variable
'r_squared' in the below cell after rounding it off to 2-decimal places
###Start code here
r_squared = 0.90
###End code(approx 1 line)