SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
A Friendly Introduction to Linear Regression
Luis Serrano
Linear Regression Logistic Regression Support Vector Machines
Series of 3 videos
What is Linear Regression?
1 room 2 rooms 3 rooms 4 rooms 5 rooms
$150K $200K $300K $350K???
$250K
Housing Prices
House 1 House 2 House 3 House 4 House 5
$100
$200
$300
$400
1 2 3 4
Number of Rooms
Price
5
$150
$50
$250
$350
House 1
House 2
House 3
House 4
House 5
$100
$200
$300
$400
1 2 3 4
Number of Rooms
Price
5
$150
$50
$250
$350
House 1 House 2
House 3
House 4
House 5
Linear Regression
Linear Regression
Linear Regression
Come
closer!
Come
closer!
Come
closer!
Come
closer!
Come
closer!
Linear Regression
Come
closer!
How do we move a line closer to a point?
Come
closer!
Moving a line
Come
closer!
y-intercept
Slope
Changing the slope - Rotation
Slope
Bigger slope
Smaller slopePivot
Changing the y-intercept - Translation
y-intercept
Smaller y-intercept
Bigger y-intercept
How to move a line
Rotate line counter-clockwise Increase slope
Rotate line clockwise Decrease slope
Translate line up Increase y-intercept
Translate line down Decrease y-intercept
Four cases
Come
closer!
Rotate counter-clockwise
translate up
Increase slope,
increase y-intercept
Four cases
Come
closer!
Rotate clockwise
translate up
Decrease slope,
increase y-intercept
Four cases
Come
closer!
Rotate counter-clockwise
translate down
increase slope,
decrease y-intercept
Four cases
Come
closer!
Rotate clockwise
translate down
Decrease slope,
decrease y-intercept
Four cases
Decrease slope,
decrease y-intercept
Increase slope,
increase y-intercept
Increase slope,
decrease y-intercept
Decrease slope,
increase y-intercept
Moving a line
Come
closer!
y-intercept = 3
y = 2x + 3
Slope = 2
y = 2.01x + 3.01
Step 1: Pick a small number.
(learning rate)
Step 2:
- Add learning rate to slope
- Add learning rate to y-intercept
0.01
+0.01 +0.01
0.010.01
Linear regression
algorithm
Come
closer!
Step 3: Pick a small number.
(learning rate)
0.01
Step 4: (repeat 1000 times)
-Pick random point
-Move line towards point
Step 2: Pick a large number.
(number of repetitions, or epochs)
1000
-If point above line, and to the right of the y-axis:
rotate counter-clockwise and translate up
-If point above line, and to the left of the y-axis:
rotate clockwise and translate up
-If point below line, and to the right of the y-axis:
rotate clockwise and translate down
-If point below line, and to the left of the y-axis:
rotate counter-clockwise and translate down
-If point above line, and to the right of the y-axis:
add 0.01 to slope
add 0.01 to y-intercept
-If point above line, and to the left of the y-axis:
subtract 0.01 to slope
add 0.01 to y-intercept
-If point below line, and to the right of the y-axis:
subtract 0.01 to slope
subtract 0.01 to y-intercept
-If point below line, and to the left of the y-axis:
add 0.01 to slope
subtract 0.01 to y-intercept
Step 1: Start with a random line
Come
closer!
Step 5: Enjoy your fitted line!
Can we do better?
Yes!
Step 3: Pick a small number.
(learning rate)
0.01
Step 4: (repeat 1000 times)
-Pick random point
-Move line towards point
Step 2: Pick a large number.
(number of repetitions, or epochs)
1000
-If point above line, and to the right of the y-axis:
rotate counter-clockwise and translate up
-If point above line, and to the left of the y-axis:
rotate clockwise and translate up
-If point below line, and to the right of the y-axis:
rotate clockwise and translate down
-If point below line, and to the left of the y-axis:
rotate counter-clockwise and translate down
-If point above line, and to the right of the y-axis:
add 0.01 to slope
add 0.01 to y-intercept
-If point above line, and to the left of the y-axis:
subtract 0.01 to slope
add 0.01 to y-intercept
-If point below line, and to the right of the y-axis:
subtract 0.01 to slope
subtract 0.01 to y-intercept
-If point below line, and to the left of the y-axis:
add 0.01 to slope
subtract 0.01 to y-intercept
Step 1: Start with a random line
Step 5: Enjoy your fitted line!
4 cases!
1 case?
Linear regression
algorithm
Positive and negative distance
+-
Positive and negative distance
+
-
Positive and negative distance
+4-4
+3-3
(2,1) (6,1)
(6,4)
6-22-64-11-4
Four cases
Decrease slope,
decrease y-intercept
Increase slope,
increase y-intercept
Increase slope,
decrease y-intercept
Decrease slope,
increase y-intercept
Four cases
+
+
Four cases
+
-
Four cases
-
-
Four cases
-
+
Decrease slope,
decrease y-intercept
Increase slope,
increase y-intercept
Increase slope,
decrease y-intercept
Decrease slope,
increase y-intercept
+
+
+
-
-
-
-
+
Four cases
Decrease slope,
decrease y-intercept
Increase slope,
increase y-intercept
Increase slope,
decrease y-intercept
Decrease slope,
increase y-intercept
+
+
+
-
-
-
-
+
Four cases
One rule to rule them all
Decrease slope,
decrease y-intercept
Increase slope,
increase y-intercept
Increase slope,
decrease y-intercept
Decrease slope,
increase y-intercept
+
+
+
-
-
-
-
+
Rule
To rotate:
- Add (vertical distance) x (horizontal
distance) to slope
To translate:
- Add (vertical distance) to y-intercept
Square trickCome
closer!
y = 2x + 3
y = 2.15x + 3.03
Step 1:
Pick a small number (learning rate) 0.01
Step 2:
- Add (learning rate) x (vertical distance) x (horizontal distance) to slope
- Add (learning rate) x (vertical distance) to y-intercept
+
+5
3
+ 0.01 x 3 x 5 + 0.01 x 3
0.01
5
3
0.01
3
+0.15 +0.03
Square trick
Come
closer!
y = 2x + 3
y = 1.8x + 2.96
Step 1:
Pick a small number (learning rate) 0.01
Step 2:
- Add (learning rate) x (vertical distance) x (horizontal distance) to slope
- Add (learning rate) x (vertical distance) to y-intercept
-
+5
-4
+ 0.01 x (-4) x 5 + 0.01 x (-4)
-4 0.010.01
-0.2 -0.04
5
-4
Linear regression
algorithm Step 3: Pick a small number.
(learning rate)
0.01
Step 4: (repeat 1000 times)
-Pick random point
-Move line towards point
Step 2: Pick a large number.
(number of repetitions, or epochs)
1000
Step 1: Start with a random line
Come
closer!
Step 5: Enjoy your fitted line!
- Add (learning rate)x(vertical distance) x
(horizontal distance) to slope
- Add (learning rate)x(vertical distance)
to y-intercept
2 Challenges
Square error
Large square error Small square error
Minimize using calculus (gradient descent)
Same as the square trick!
Bad line Good line
Absolute error
Large absolute error Small absolute error
Minimize using calculus (gradient descent)
Develop an absolute trick!
Bad line Good line
Absolute trick
Step 1:
Pick a small number (learning rate)
Step 2:
- If point is above the line:
- Add (learning rate) x (horizontal distance) to slope
- Add (learning rate) to y-intercept
- If point is below the line:
- Subtract (learning rate) x (horizontal distance) to slope
- Subtract (learning rate) to y-intercept
Come
closer!
Linear Regression Logistic Regression Support Vector Machines
Series of 3 videos
Thank you!
@luis_likes_math
Subscribe, like,
share, comment!
youtube.com/c/LuisSerrano

Weitere ähnliche Inhalte

Was ist angesagt?

12.5. vector valued functions
12.5. vector valued functions12.5. vector valued functions
12.5. vector valued functions
math267
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
Simplilearn
 
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Simplilearn
 
σπαθάρας δημήτριος διδακτικό υλικό γλκατ τεύχος 1
σπαθάρας δημήτριος   διδακτικό υλικό γλκατ τεύχος 1σπαθάρας δημήτριος   διδακτικό υλικό γλκατ τεύχος 1
σπαθάρας δημήτριος διδακτικό υλικό γλκατ τεύχος 1
Christos Loizos
 

Was ist angesagt? (20)

12.5. vector valued functions
12.5. vector valued functions12.5. vector valued functions
12.5. vector valued functions
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
 
04 cours matrices_suites
04 cours matrices_suites04 cours matrices_suites
04 cours matrices_suites
 
Radial Basis Function Interpolation
Radial Basis Function InterpolationRadial Basis Function Interpolation
Radial Basis Function Interpolation
 
Prime
PrimePrime
Prime
 
LZ78
LZ78LZ78
LZ78
 
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
Support Vector Machine - How Support Vector Machine works | SVM in Machine Le...
 
Topological Sort Algorithm.pptx
Topological Sort Algorithm.pptxTopological Sort Algorithm.pptx
Topological Sort Algorithm.pptx
 
Lecture10 - Naïve Bayes
Lecture10 - Naïve BayesLecture10 - Naïve Bayes
Lecture10 - Naïve Bayes
 
Linear models for classification
Linear models for classificationLinear models for classification
Linear models for classification
 
Random forest sgv_ai_talk_oct_2_2018
Random forest sgv_ai_talk_oct_2_2018Random forest sgv_ai_talk_oct_2_2018
Random forest sgv_ai_talk_oct_2_2018
 
Singular value decomposition (SVD)
Singular value decomposition (SVD)Singular value decomposition (SVD)
Singular value decomposition (SVD)
 
1.3 solving equations t
1.3 solving equations t1.3 solving equations t
1.3 solving equations t
 
NAIVE BAYES CLASSIFIER
NAIVE BAYES CLASSIFIERNAIVE BAYES CLASSIFIER
NAIVE BAYES CLASSIFIER
 
PCA (Principal Component Analysis)
PCA (Principal Component Analysis)PCA (Principal Component Analysis)
PCA (Principal Component Analysis)
 
Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)Knapsack Problem (DP & GREEDY)
Knapsack Problem (DP & GREEDY)
 
5.3 mining sequential patterns
5.3 mining sequential patterns5.3 mining sequential patterns
5.3 mining sequential patterns
 
σπαθάρας δημήτριος διδακτικό υλικό γλκατ τεύχος 1
σπαθάρας δημήτριος   διδακτικό υλικό γλκατ τεύχος 1σπαθάρας δημήτριος   διδακτικό υλικό γλκατ τεύχος 1
σπαθάρας δημήτριος διδακτικό υλικό γλκατ τεύχος 1
 
Naive Bayes Classifier
Naive Bayes ClassifierNaive Bayes Classifier
Naive Bayes Classifier
 
Support Vector Machine without tears
Support Vector Machine without tearsSupport Vector Machine without tears
Support Vector Machine without tears
 

Ähnlich wie Linear regression (6)

04_magic_square.pdf
04_magic_square.pdf04_magic_square.pdf
04_magic_square.pdf
 
Teacherlecture
TeacherlectureTeacherlecture
Teacherlecture
 
3.3g
3.3g3.3g
3.3g
 
Logistic regression
Logistic regressionLogistic regression
Logistic regression
 
kinematics-graphing.ppt
kinematics-graphing.pptkinematics-graphing.ppt
kinematics-graphing.ppt
 
Math Lecture 11 (Cartesian Coordinates)
Math Lecture 11 (Cartesian Coordinates)Math Lecture 11 (Cartesian Coordinates)
Math Lecture 11 (Cartesian Coordinates)
 

Kürzlich hochgeladen

➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
amitlee9823
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
only4webmaster01
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Kürzlich hochgeladen (20)

Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdfAccredited-Transport-Cooperatives-Jan-2021-Web.pdf
Accredited-Transport-Cooperatives-Jan-2021-Web.pdf
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
Chintamani Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore ...
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 

Linear regression

  • 1. A Friendly Introduction to Linear Regression Luis Serrano
  • 2. Linear Regression Logistic Regression Support Vector Machines Series of 3 videos
  • 3. What is Linear Regression?
  • 4. 1 room 2 rooms 3 rooms 4 rooms 5 rooms $150K $200K $300K $350K??? $250K Housing Prices House 1 House 2 House 3 House 4 House 5
  • 5. $100 $200 $300 $400 1 2 3 4 Number of Rooms Price 5 $150 $50 $250 $350 House 1 House 2 House 3 House 4 House 5
  • 6. $100 $200 $300 $400 1 2 3 4 Number of Rooms Price 5 $150 $50 $250 $350 House 1 House 2 House 3 House 4 House 5
  • 11. How do we move a line closer to a point? Come closer!
  • 13. Changing the slope - Rotation Slope Bigger slope Smaller slopePivot
  • 14. Changing the y-intercept - Translation y-intercept Smaller y-intercept Bigger y-intercept
  • 15. How to move a line Rotate line counter-clockwise Increase slope Rotate line clockwise Decrease slope Translate line up Increase y-intercept Translate line down Decrease y-intercept
  • 16. Four cases Come closer! Rotate counter-clockwise translate up Increase slope, increase y-intercept
  • 17. Four cases Come closer! Rotate clockwise translate up Decrease slope, increase y-intercept
  • 18. Four cases Come closer! Rotate counter-clockwise translate down increase slope, decrease y-intercept
  • 19. Four cases Come closer! Rotate clockwise translate down Decrease slope, decrease y-intercept
  • 20. Four cases Decrease slope, decrease y-intercept Increase slope, increase y-intercept Increase slope, decrease y-intercept Decrease slope, increase y-intercept
  • 21. Moving a line Come closer! y-intercept = 3 y = 2x + 3 Slope = 2 y = 2.01x + 3.01 Step 1: Pick a small number. (learning rate) Step 2: - Add learning rate to slope - Add learning rate to y-intercept 0.01 +0.01 +0.01 0.010.01
  • 22. Linear regression algorithm Come closer! Step 3: Pick a small number. (learning rate) 0.01 Step 4: (repeat 1000 times) -Pick random point -Move line towards point Step 2: Pick a large number. (number of repetitions, or epochs) 1000 -If point above line, and to the right of the y-axis: rotate counter-clockwise and translate up -If point above line, and to the left of the y-axis: rotate clockwise and translate up -If point below line, and to the right of the y-axis: rotate clockwise and translate down -If point below line, and to the left of the y-axis: rotate counter-clockwise and translate down -If point above line, and to the right of the y-axis: add 0.01 to slope add 0.01 to y-intercept -If point above line, and to the left of the y-axis: subtract 0.01 to slope add 0.01 to y-intercept -If point below line, and to the right of the y-axis: subtract 0.01 to slope subtract 0.01 to y-intercept -If point below line, and to the left of the y-axis: add 0.01 to slope subtract 0.01 to y-intercept Step 1: Start with a random line Come closer! Step 5: Enjoy your fitted line!
  • 23. Can we do better? Yes!
  • 24. Step 3: Pick a small number. (learning rate) 0.01 Step 4: (repeat 1000 times) -Pick random point -Move line towards point Step 2: Pick a large number. (number of repetitions, or epochs) 1000 -If point above line, and to the right of the y-axis: rotate counter-clockwise and translate up -If point above line, and to the left of the y-axis: rotate clockwise and translate up -If point below line, and to the right of the y-axis: rotate clockwise and translate down -If point below line, and to the left of the y-axis: rotate counter-clockwise and translate down -If point above line, and to the right of the y-axis: add 0.01 to slope add 0.01 to y-intercept -If point above line, and to the left of the y-axis: subtract 0.01 to slope add 0.01 to y-intercept -If point below line, and to the right of the y-axis: subtract 0.01 to slope subtract 0.01 to y-intercept -If point below line, and to the left of the y-axis: add 0.01 to slope subtract 0.01 to y-intercept Step 1: Start with a random line Step 5: Enjoy your fitted line! 4 cases! 1 case? Linear regression algorithm
  • 25. Positive and negative distance +-
  • 26. Positive and negative distance + -
  • 27. Positive and negative distance +4-4 +3-3 (2,1) (6,1) (6,4) 6-22-64-11-4
  • 28. Four cases Decrease slope, decrease y-intercept Increase slope, increase y-intercept Increase slope, decrease y-intercept Decrease slope, increase y-intercept
  • 33. Decrease slope, decrease y-intercept Increase slope, increase y-intercept Increase slope, decrease y-intercept Decrease slope, increase y-intercept + + + - - - - + Four cases
  • 34. Decrease slope, decrease y-intercept Increase slope, increase y-intercept Increase slope, decrease y-intercept Decrease slope, increase y-intercept + + + - - - - + Four cases
  • 35. One rule to rule them all Decrease slope, decrease y-intercept Increase slope, increase y-intercept Increase slope, decrease y-intercept Decrease slope, increase y-intercept + + + - - - - + Rule To rotate: - Add (vertical distance) x (horizontal distance) to slope To translate: - Add (vertical distance) to y-intercept
  • 36. Square trickCome closer! y = 2x + 3 y = 2.15x + 3.03 Step 1: Pick a small number (learning rate) 0.01 Step 2: - Add (learning rate) x (vertical distance) x (horizontal distance) to slope - Add (learning rate) x (vertical distance) to y-intercept + +5 3 + 0.01 x 3 x 5 + 0.01 x 3 0.01 5 3 0.01 3 +0.15 +0.03
  • 37. Square trick Come closer! y = 2x + 3 y = 1.8x + 2.96 Step 1: Pick a small number (learning rate) 0.01 Step 2: - Add (learning rate) x (vertical distance) x (horizontal distance) to slope - Add (learning rate) x (vertical distance) to y-intercept - +5 -4 + 0.01 x (-4) x 5 + 0.01 x (-4) -4 0.010.01 -0.2 -0.04 5 -4
  • 38. Linear regression algorithm Step 3: Pick a small number. (learning rate) 0.01 Step 4: (repeat 1000 times) -Pick random point -Move line towards point Step 2: Pick a large number. (number of repetitions, or epochs) 1000 Step 1: Start with a random line Come closer! Step 5: Enjoy your fitted line! - Add (learning rate)x(vertical distance) x (horizontal distance) to slope - Add (learning rate)x(vertical distance) to y-intercept
  • 40. Square error Large square error Small square error Minimize using calculus (gradient descent) Same as the square trick! Bad line Good line
  • 41. Absolute error Large absolute error Small absolute error Minimize using calculus (gradient descent) Develop an absolute trick! Bad line Good line
  • 42. Absolute trick Step 1: Pick a small number (learning rate) Step 2: - If point is above the line: - Add (learning rate) x (horizontal distance) to slope - Add (learning rate) to y-intercept - If point is below the line: - Subtract (learning rate) x (horizontal distance) to slope - Subtract (learning rate) to y-intercept Come closer!
  • 43. Linear Regression Logistic Regression Support Vector Machines Series of 3 videos
  • 44. Thank you! @luis_likes_math Subscribe, like, share, comment! youtube.com/c/LuisSerrano