prof. seungchul lee industrial ai lab. · 2020-06-29 · linear regression • 𝑦𝑦 𝑖𝑖 =...

25
Regression Prof. Seungchul Lee Industrial AI Lab.

Upload: others

Post on 07-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Regression

Prof. Seungchul LeeIndustrial AI Lab.

Page 2: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Assumption: Linear Model

• In many cases, a linear model is used to predict 𝑦𝑦𝑖𝑖

2

Page 3: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Linear Regression

• �𝑦𝑦𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖 ,𝜃𝜃) in general• In many cases, a linear model is assumed to predict 𝑦𝑦𝑖𝑖

• �𝑦𝑦𝑖𝑖 : predicted output

• 𝜃𝜃 = 𝜃𝜃0𝜃𝜃1

: model parameters

3

Page 4: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Linear Regression as Optimization

• How to find model parameters 𝜃𝜃 = 𝜃𝜃0𝜃𝜃1

• Optimization problem

4

Page 5: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Re-cast Problem as Least Squares

• For convenience, we define a function that maps inputs to feature vectors, 𝜙𝜙

5

Page 6: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Optimization

• Scalar Objective: 𝐽𝐽 = 𝐴𝐴𝑥𝑥 − 𝑦𝑦 2

6

Page 7: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Solve using Linear Algebra

• known as least square

7

Page 8: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Solve using Linear Algebra

8

Page 9: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Scikit-Learn

• Machine Learning in Python• Simple and efficient tools for data mining and data analysis• Accessible to everybody, and reusable in various contexts• Built on NumPy, SciPy, and matplotlib• Open source, commercially usable - BSD license• https://scikit-learn.org/stable/index.html#

9

Page 10: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Scikit-Learn

10

Page 11: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Scikit-Learn: Regression

11

Page 12: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Scikit-Learn: Regression

12

Page 13: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Overfitting

Industrial AI Lab.Prof. Seungchul Lee

Page 14: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Polynomial Regression (d = 1)

14

Page 15: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Polynomial Regression (d = 2)

15

Page 16: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Polynomial Regression (d = 3)

16

Page 17: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Polynomial Regression (d = 4)

17

Page 18: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Polynomial Regression (d = 5)

18

Page 19: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Polynomial Regression (d = 6)

19

Page 20: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Polynomial Regression (d = 7)

20

Page 21: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Polynomial Regression (d = 8)

21

Page 22: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Polynomial Regression (d = 9)

22

Page 23: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Overfitting Problem

• Have you come across a situation where your model performed exceptionally well on train data, but was not able to predict test data ?

• One of the most common problem data science professionals face is to avoid overfitting.

23

Page 24: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Issue with Rich Representation

• Low error on input data points, but high error nearby• Low error on training data, but high error on testing data

24

Page 25: Prof. Seungchul Lee Industrial AI Lab. · 2020-06-29 · Linear Regression • 𝑦𝑦 𝑖𝑖 = 𝑓𝑓(𝑥𝑥𝑖𝑖,𝜃𝜃)in general • In many cases, a linear model

Regularization (Shrinkage Methods)

• Often, overfitting associated with very large estimated parameters• We want to balance

– how well function fits data– magnitude of coefficients

– multi-objective optimization– 𝜆𝜆 is a tuning parameter

25