0% found this document useful (0 votes)
15 views2 pages

Experiment No 2

Uploaded by

21bme145
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Experiment No 2

Uploaded by

21bme145
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment 2

Machine learning through Linear


Regression
Linear regression is a very simple approach for supervised learning. In particular, linear
regression is a useful tool for predicting a quantitative response. linear regression is still a
useful and widely used statistical learning method.

Simple Linear Regression

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

Machine learning approach


The regression model which is linear in nature is deployed through hypothesis function
^y =h(x)=w 0+ w1 x

The above said function is for single input variable/feature.


The cost function can be derived as
n
J=∑ ( y i− ^y i)2
i=1

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.

Assessing Model Accuracy


This is typically referred to as the goodness-of-fit. The R2 statistic provides an alternative measure of
fit. It represents the proportion of variance explained and so it always takes on a value between 0 and
1, and is independent of the scale of Y. R is simply a function of residual sum of squares (RSS) and
2

total sum of squares (TSS):


n

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.

You might also like