class: title-slide, center # Lecture 12: Simple Linear Regression ## Introducing (revisiting) a less-simple model ### Data 100 Spring 2021 --- class: center, middle # What is a *model*? > A useful simplification of reality. --- ## The modeling process: 3 steps ### I. Choose a model -- - Constant model `\(\hat{y} = \theta\)` - `\(\hat{y}\)` is a prediction, `\(\theta\)` is a parameter -- ### II. Choose an objective function -- - Loss functions - Squared loss: `\(L_2(y, \hat{y}) = (y - \hat{y})^2\)` - Absolute loss: `\(L_1(y, \hat{y}) = |y - \hat{y}|\)` -- ### III. Fit the model by optimizing your objective function -- - Analytical approach - Calculus --- ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-3-1.png" width="504" /> ] .left-column[ ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-4-1.png" width="504" /> ] .left-column[ ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-5-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157$$` ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-6-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157$$` ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-7-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157$$` ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-8-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157$$` ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-9-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157 \\ MSE = .00211$$` ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-10-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157 \\ MSE = .00211$$` *Can we improve the prediction?* ] --- ## Modeling tip rate .right-column[ ![](lec-12-1_files/figure-html/unnamed-chunk-11-1.gif)<!-- --> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157 \\ MSE = .00211$$` *Can we improve the prediction?* ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-12-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157 \\ MSE = .00211$$` *Can we improve the prediction?* ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-13-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157 \\ MSE = .00211$$` *Can we improve the prediction?* **Linear Model** with ? loss `$$\hat{y} = \theta_0 + \theta_1 x$$` ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-14-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157 \\ MSE = .00211$$` *Can we improve the prediction?* **Linear Model** with ? loss `$$\hat{y} = \theta_0 + \theta_1 x$$` *Did it help?* ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-15-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157 \\ MSE = .00211$$` *Can we improve the prediction?* **Linear Model** with ? loss `$$\hat{y} = \theta_0 + \theta_1 x$$` *Did it help?* ] --- class: animated, fadeIn ## Modeling tip rate .right-column[ <img src="lec-12-1_files/figure-html/unnamed-chunk-16-1.png" width="504" /> ] .left-column[ **Constant Model** with L2 loss `$$\hat{y} = .157 \\ MSE = .00211$$` *Can we improve the prediction?* **Linear Model** with ? loss `$$\hat{y} = \theta_0 + \theta_1 x$$` *Did it help?* ] --- ## Comparing Models .pull-left[ ### Constant Model `$$\hat{y} = \theta$$` **Useful** - Desc: average tip - Pred: `\(MSE = .0021\)` **Simple** - 1 parameter <img src="lec-12-1_files/figure-html/unnamed-chunk-18-1.png" width="144" style="display: block; margin: auto;" /> ] -- .pull-right[ ### Simple Linear Model `$$\hat{y} = \theta_0 + \theta_1 x$$` **Useful** - Desc: negative assoc. - Pred: `\(MSE = ?\)` **Simple** - 2 parameters <img src="lec-12-1_files/figure-html/unnamed-chunk-19-1.png" width="144" style="display: block; margin: auto;" /> ]