Professional Documents
Culture Documents
Linear Regression
Univariate Linear Regression
• Let’s say we want to predict the price for a
house that is let’s say 1750 square feet,
• We would need to first draw some line of best
fit.
• This is an example of a regression problem
where we are trying to predict a real-valued
output
• The line of best fit drawn represents a simple
linear regression model
Notation:
• n – number of training examples
• m – number of features in our dataset
• x – input variable/ feature
• y – output variable/target variable
• (xi, yi) – ith training example
• In supervised machine learning, we feed a
training set to a learning algorithm
• The learning algorithm has to give us a
function that maps the input to a predicted
output
Cost function
• Our function f can be represented as:
• and are called weights
• When trying to come up with a model that
best fits our training data, we have to choose
the right values for and
• Let’s look at how different choices of and
would affect our model…..
• We need to choose values of and so that
(predicted value) is as close as possible to for
our training examples
• So the goal is to minimize which leads us to
the MSE (min squared error function)
• for n- training examples
• Hence we need to
• Let’s assume we have the following examples
from a training set:
0 3
1 0
2 11
3 44
• The plot of shows that the minimum value is
obtained when = 1.
• Hence the best model to fit our data would
be:
Gradient descent algorithm
• Procedure:
– Start with some ,…
– Keep changing ,… to reduce until we hopefully
end at a minimum
• Weights are changed using the formula below:
,for
α – learning rate
NB: The weights must be simultaneously
updated!
• Let’s look at an example:
• Using , let’s try to find and that will give us
the minimum value of our MSE loss function
for the training set below:
• Making predictions