Regression and Classification
Regression and Classification
Regression and Classification
Classification
Datasets in univariate
setting
𝑥3
𝑦3
x1 y
0.00632 24
0.02731 21.6
0.02729 34.7
0.03237 33.4
0.06905 36.2
0.02985 28.7
0.08829 22.9
0.14455 27.1
0.21124 16.5
0.17004 18.9
0.22489 15
0.11747 18.9
0.09378 21.7
0.62976 20.4
0.63796 18.2
0.62739 19.9
1.05393 23.1
0.7842 17.5
0.80271 20.2
0.7258 18.2
Linear Regression Hypothesis
(Model)
In matrix form
• ℎ𝜃 𝑥 =
• This
𝜃 𝑇 𝑥 is not just fancy math. This is important for implementation!
Why?
Linear Regression Cost
Function
ℎ𝜃 𝑥 = 70 + 0.2𝑥1 + 0.01𝑥 2 + 4𝑥 3 − 𝑥4
+
Cost function for one data point
�
�
−
�
�
�
�
�
�
Logistic Regression (Classification)
Hypothesis
1
ℎ𝜃 𝑥 = 1
+
Cost function for one data point
�
�
𝐽(ℎ𝜃 𝑥 , 𝑦) = −ylog(ℎ
− 𝜃 𝑥 ) − (1 − 𝑦)log(1
�
− ℎ𝜃 𝑥 ) �
�
Cost function as all data points �
�
�
Logistic
Regression
• To see how we can minimize this hypothesis error we need to take
the derivative of the cost function as in the linear regression case
Logistic Regression error
minimization
𝜕𝐽(ℎ𝜃 𝑥 , 𝑦) ℎ 𝜃 𝑥 − 𝑦 𝑥𝑗
𝜕𝜃𝑗 =
• The previous formula minimizing the error for individual data point
• So if you would like to minimize for all data points on average, then we
need to take the sum and divide by m
Gradient Decent
Regressions
Linear Regression Logistic Regression (Classification)
Technically we do not need to calculate the cost function in the Gradient decent case