Experiment No 2
Experiment No 2
Simple linear regression lives up to its name: it is a very straightforward approach for
predicting a quantitative response Y. On the basis of a single predictor variable X. It assumes
that there is approximately a linear relationship between X and Y.
y=w0 + w1 x +ϵ
Y = Output variable
X = Input variable
The cost function can be minimized using gradient decent approach to estimate the optimal value of
w0 and w1 weighting coefficients.
Model building in R
To build this model in R, the formula used notation of y x.
model <- lm (Y ~ X, data)
In the background the lm, which stands for “linear model”, is producing the best-fit linear relationship
by minimizing the least squares criterion.
For initial assessment of our model we can use summary. This provides us with a host of information
about our model.
RSS
∑ ( y i− ^y i)2
R2=1− =1− i=1
n
TSS
∑ ( y i− y i)2
i=1
Exercise
1. Prepare R code for preforming linear regression prediction of a given dataset using gradient
descent as optimization technique for minimizing the cost function. Consider single
dependent and single independent variable for the same.
2. A database containing compressive strength of concrete is shared with you on LMS platform.
Build a linear regression model to predict the compressive strength of the concrete with
respect to other given parameter. Cross validate the model with 10 fold cross validation
strategy. Estimate the average MSE for cross validation.