Lec06-PracticalML
Lec06-PracticalML
Price
Price
Size Size Size
x2 x2 x2
x1 x1 x1
( = sigmoid function)
Practical ML
Regularization
Machine Learning
Intuition
Price
Price
𝑛 2
σ
+ 𝜆 𝑗=1 𝜃𝑗
Regularization.
Price
Size of house
In regularized linear regression, we choose to minimize
Size of house
Practical ML
Regularized Linear
regression
Machine Learning
Regularized linear regression
Gradient descent
Repeat
𝜆
− 𝜃𝑗
𝑚
Practical ML
Regularized logistic
regression
Machine Learning
Regularized logistic regression.
x2
x1
Cost function:
𝑛
𝜆
+ 𝜃𝑗2
2𝑚
𝑗=1
Gradient descent
Repeat
𝜆
− 𝜃𝑗
𝑚
Practical ML
Model Selection
Machine Learning
Evaluating the hypothesis
Dataset:
Size Price
2104 400
1600 330
2400 369
1416 232
3000 540
1985 300
1534 315
1427 199
1380 212
1494 243
Training/testing procedure for linear regression
𝑚𝑡𝑒𝑠𝑡
1 𝑖 𝑖 2
𝐽 𝜃 = (ℎ 𝑥 ) − 𝑦
2𝑚𝑡𝑒𝑠𝑡
𝑖=1
Model selection
Test error:
Practical ML
Bias-Variance
Tradeoff
Machine Learning
Bias error: error from erroneous
assumptions in the learning algorithm
(under fitting)
Price
Price
Size Size Size
(cross validation
error)
𝐽𝑡𝑟𝑎𝑖𝑛 𝜃 ≈ 𝐽𝑐𝑣 𝜃
Variance (overfit):
(training error) 𝐽𝑡𝑟𝑎𝑖𝑛 𝜃 will be low
𝐽𝑡𝑟𝑎𝑖𝑛 𝜃 << 𝐽𝑐𝑣 𝜃
degree of
polynomial d
Practical ML
Regularization and
bias/variance
Machine Learning
Linear regression with regularization
Model:
Price
Price
Price
Size Size Size
Large xx Intermediate xx Small xx
High bias (underfit) “Just right” High variance (overfit)
Choosing the regularization parameter
Choosing the regularization parameter
Model:
1. Try
2. Try
3. Try
4. Try
5. Try
12. Try
Bias/variance as a function of the regularization parameter
Debugging a learning algorithm:
Suppose you have implemented regularized linear regression to predict
housing prices. However, when you test your hypothesis in a new set of
houses, you find that it makes unacceptably large errors in its
prediction. What should you try next?
Machine Learning
Cancer classification example
Train logistic regression model .( if cancer,
otherwise)
Find that you got 1% error on test set.
(99% correct diagnoses)
Logistic regression:
Predict 1 if
Predict 0 if
Suppose we want to predict (cancer)
only if very confident. (set high threshold)
High Precision, low threshold
Suppose we want to avoid missing too many cases of
cancer (avoid false negatives). (set low threshold)
High Recall, low Precision
More generally: Predict 1 if threshold.
F1 Score (F score):