CS6220: Data Mining Techniques - Computer Science

32
CS6220: DATA MINING TECHNIQUES Instructor: Yizhou Sun [email protected] January 19, 2016 Matrix Data: Prediction

Transcript of CS6220: Data Mining Techniques - Computer Science

Page 1: CS6220: Data Mining Techniques - Computer Science

CS6220: DATA MINING TECHNIQUES

Instructor: Yizhou [email protected]

January 19, 2016

Matrix Data: Prediction

Page 2: CS6220: Data Mining Techniques - Computer Science

Announcements

•Team formation due next Wednesday

•Homework 1 out by tomorrow

2

Page 3: CS6220: Data Mining Techniques - Computer Science

Today’s Schedule

•Course Project Introduction

•Linear Regression Model

•Decision Tree

3

Page 4: CS6220: Data Mining Techniques - Computer Science

Methods to LearnMatrix Data Text

DataSet Data Sequence

DataTime Series Graph &

NetworkImages

Classification Decision Tree; Naïve Bayes; Logistic RegressionSVM; kNN

HMM Label Propagation

Neural Network

Clustering K-means; hierarchicalclustering; DBSCAN; Mixture Models; kernel k-means*

PLSA SCAN; Spectral Clustering

FrequentPattern Mining

Apriori; FP-growth

GSP; PrefixSpan

Prediction Linear Regression Autoregression Collaborative Filtering

Similarity Search

DTW P-PageRank

Ranking PageRank

4

Page 5: CS6220: Data Mining Techniques - Computer Science

How to learn these algorithms?

•Three levels

•When it is applicable?

• Input, output, strengths, weaknesses, time complexity

•How it works?

• Pseudo-code, work flows, major steps

• Can work out a toy problem by pen and paper

•Why it works?

• Intuition, philosophy, objective, derivation, proof

5

Page 6: CS6220: Data Mining Techniques - Computer Science

Matrix Data: Prediction

•Matrix Data

•Linear Regression Model

•Model Evaluation and Selection

•Summary

6

Page 7: CS6220: Data Mining Techniques - Computer Science

Example

7

npx...

nfx...

n1x

...............

ipx...

ifx...

i1x

...............

1px...

1fx...

11xA matrix of n × 𝑝:

• n data objects / points• p attributes / dimensions

Page 8: CS6220: Data Mining Techniques - Computer Science

Attribute Type

•Numerical

•E.g., height, income

•Categorical / discrete

•E.g., Sex, Race

8

Page 9: CS6220: Data Mining Techniques - Computer Science

Categorical Attribute Types• Nominal: categories, states, or “names of things”

• Hair_color = {auburn, black, blond, brown, grey, red, white}

• marital status, occupation, ID numbers, zip codes

• Binary

• Nominal attribute with only 2 states (0 and 1)

• Symmetric binary: both outcomes equally important

• e.g., gender

• Asymmetric binary: outcomes not equally important.

• e.g., medical test (positive vs. negative)

• Convention: assign 1 to most important outcome (e.g., HIV positive)

• Ordinal

• Values have a meaningful order (ranking) but magnitude between successive values is not known.

• Size = {small, medium, large}, grades, army rankings

9

Page 10: CS6220: Data Mining Techniques - Computer Science

Matrix Data: Prediction

•Matrix Data

•Linear Regression Model

•Model Evaluation and Selection

•Summary

10

Page 11: CS6220: Data Mining Techniques - Computer Science

Linear Regression

•Ordinary Least Square Regression

•Closed form solution

•Gradient descent

•Linear Regression with Probabilistic Interpretation

11

Page 12: CS6220: Data Mining Techniques - Computer Science

The Linear Regression Problem

•Any Attributes to Continuous Value: x ⇒ y

• {age; major ; gender; race} ⇒ GPA

• {income; credit score; profession} ⇒ loan

• {college; major ; GPA} ⇒ future income

• ...

12

Page 13: CS6220: Data Mining Techniques - Computer Science

Illustration

13

Page 14: CS6220: Data Mining Techniques - Computer Science

Formalization

•Data: n independent data objects• 𝑦𝑖 , i = 1, … , 𝑛

• 𝒙𝑖 = 𝑥𝑖0, 𝑥𝑖1, 𝑥𝑖2, … , 𝑥𝑖𝑝T, i = 1, … , 𝑛

• A constant factor is added to model the bias term, i. e. , 𝑥𝑖0 = 1

•Model:• 𝑦: dependent variable• 𝒙: explanatory variables

•𝜷 = 𝛽0, 𝛽1, … , 𝛽𝑝𝑇: 𝑤𝑒𝑖𝑔ℎ𝑡 𝑣𝑒𝑐𝑡𝑜𝑟

• 𝑦 = 𝒙𝑇𝜷 = 𝛽0 + 𝑥1𝛽1 + 𝑥2𝛽2 + ⋯ + 𝑥𝑝𝛽𝑝

14

Page 15: CS6220: Data Mining Techniques - Computer Science

A 2-step Process

•Model Construction

•Use training data to find the best parameter 𝜷,

denoted as 𝜷

•Model Usage

•Model Evaluation

• Use validation data to select the best model• Feature selection

•Apply the model to the unseen data (test data):

𝑦 = 𝒙𝑇 𝜷

15

Page 16: CS6220: Data Mining Techniques - Computer Science

Least Square Estimation

•Cost function (Total Square Error):

• 𝐽 𝜷 = 𝑖 𝒙𝑖𝑇𝜷 − 𝑦𝑖

2

•Matrix form:

• 𝐽 𝜷 = X𝜷 − 𝒚 𝑇(𝑋𝜷 − 𝒚)

or X𝜷 − 𝒚2

16𝑿: 𝒏 × 𝒑 + 𝟏 matrix

npx...

nfx...

n1x

...............

ipx...

ifx...

i1x

...............

1px...

1fx...

11x

,1

,1

,1𝑦1

⋮𝑦𝑖

⋮𝑦𝑛

y: 𝒏 × 𝟏 𝐯𝐞𝐜𝐭𝐨𝐫

Page 17: CS6220: Data Mining Techniques - Computer Science

Ordinary Least Squares (OLS)

•Goal: find 𝜷 that minimizes 𝐽 𝜷• 𝐽 𝜷 = X𝜷 − 𝑦 𝑇 𝑋𝜷 − 𝑦

= 𝜷𝑇𝑋𝑇𝑋𝜷 − 𝑦𝑇𝑋𝜷 − 𝜷𝑇𝑋𝑇𝑦 + 𝑦𝑇𝑦

•Ordinary least squares

•Set first derivative of 𝐽 𝜷 as 0

•𝜕𝐽

𝜕𝜷= 2𝜷𝑇XTX − 2𝑦𝑇𝑋 = 0

• ⇒ 𝜷 = 𝑋𝑇𝑋−1

𝑋𝑇𝑦

17

Page 18: CS6220: Data Mining Techniques - Computer Science

Gradient Descent

•Minimize the cost function by moving down in the steepest direction

18

Page 19: CS6220: Data Mining Techniques - Computer Science

Batch Gradient Descent

•Move in the direction of steepest descend

Repeat until converge {

}

19

𝜷(𝑡+1):=𝜷(t) − 𝜂𝜕𝐽

𝜕𝜷 𝜷=𝜷(t) ,

Where 𝐽 𝜷 = 𝑖 𝒙𝑖𝑇𝜷 − 𝑦𝑖

2= 𝑖 𝐽𝑖(𝜷) and

𝜕𝐽

𝜕𝜷=

𝑖

𝜕𝐽𝑖𝜕𝜷

=

𝑖

2𝒙𝑖 (𝒙𝑖𝑇𝜷 − 𝑦𝑖)

e.g., 𝜂 = 0.1

Page 20: CS6220: Data Mining Techniques - Computer Science

Stochastic Gradient Descent

•When a new observation, i, comes in, update

weight immediately (extremely useful for large-

scale datasets):

Repeat {

for i=1:n {

𝜷(𝑡+1):=𝜷(t) + 2𝜂(𝑦𝑖 − 𝒙𝑖𝑇𝜷(𝑡))𝒙𝑖

}

}

20

If the prediction for object i is smaller than the real value,

𝜷 should move forward to the direction of 𝒙𝑖

Page 21: CS6220: Data Mining Techniques - Computer Science

Other Practical Issues

•What if 𝑋𝑇𝑋 is not invertible?•Add a small portion of identity matrix, λ𝐼, to it (ridge regression* )

•What if some attributes are categorical?•Set dummy variables

• E.g., 𝑥 = 1, 𝑖𝑓 𝑠𝑒𝑥 = 𝐹; 𝑥 = 0, 𝑖𝑓 𝑠𝑒𝑥 = 𝑀

• Nominal variable with multiple values? • Create more dummy variables for one variable

•What if non-linear correlation exists?•Transform features, say, 𝑥 to 𝑥2

21

Page 22: CS6220: Data Mining Techniques - Computer Science

Probabilistic Interpretation

•Review of normal distribution

•X~𝑁 𝜇, 𝜎2 ⇒ 𝑓 𝑋 = 𝑥 =1

2𝜋𝜎2 𝑒−

𝑥−𝜇 2

2𝜎2

22

Page 23: CS6220: Data Mining Techniques - Computer Science

Probabilistic Interpretation

•Model: 𝑦𝑖 = 𝑥𝑖𝑇𝛽 + ε𝑖

• ε𝑖~𝑁(0, 𝜎2)

• 𝑦𝑖 𝑥𝑖 , 𝛽~𝑁(𝑥𝑖𝑇𝛽, 𝜎2)

• 𝐸 𝑦𝑖 𝑥𝑖 = 𝑥𝑖𝑇𝛽

• Likelihood:

• 𝐿 𝜷 = 𝑖 𝑝 𝑦𝑖 𝑥𝑖 , 𝛽)

= 𝑖1

2𝜋𝜎2exp{−

𝑦𝑖−𝒙𝑖𝑇𝜷

2

2𝜎2 }

•Maximum Likelihood Estimation

• find 𝜷 that maximizes L 𝜷

• arg max 𝐿 = arg min 𝐽, Equivalent to OLS!

23

Page 24: CS6220: Data Mining Techniques - Computer Science

Matrix Data: Prediction

•Matrix Data

•Linear Regression Model

•Model Evaluation and Selection

•Summary

24

Page 25: CS6220: Data Mining Techniques - Computer Science

Model Selection Problem

• Basic problem: • how to choose between competing linear regression

models

•Model too simple: • “underfit” the data; poor predictions; high bias; low

variance

•Model too complex: • “overfit” the data; poor predictions; low bias; high

variance

•Model just right: • balance bias and variance to get good predictions

25

Page 26: CS6220: Data Mining Techniques - Computer Science

Bias and Variance

• Bias: 𝐸( 𝑓 𝑥 ) − 𝑓(𝑥)• How far away is the expectation of the estimator to the true

value? The smaller the better.

•Variance: 𝑉𝑎𝑟 𝑓 𝑥 = 𝐸[ 𝑓 𝑥 − 𝐸 𝑓 𝑥2

]

• How variant is the estimator? The smaller the better.

• Reconsider mean square error

• 𝐽 𝜷 /𝑛 = 𝑖 𝒙𝑖𝑇 𝜷 − 𝑦𝑖

2/𝑛

• Can be considered as

• 𝐸[ 𝑓 𝑥 − 𝑓(𝑥) − 𝜀2] = 𝑏𝑖𝑎𝑠2 + 𝑣𝑎𝑟𝑖𝑎𝑛𝑐𝑒 + 𝑛𝑜𝑖𝑠𝑒

26

Note 𝐸 𝜀 = 0, 𝑉𝑎𝑟 𝜀 = 𝜎2

True predictor 𝑓 𝑥 : 𝑥𝑇𝜷

Estimated predictor 𝑓 𝑥 : 𝑥𝑇 𝜷

Page 27: CS6220: Data Mining Techniques - Computer Science

Bias-Variance Trade-off

27

Page 28: CS6220: Data Mining Techniques - Computer Science

Cross-Validation

•Partition the data into K folds

•Use K-1 fold as training, and 1 fold as testing

•Calculate the average accuracy best on K

training-testing pairs

• Accuracy on validation/test dataset!

• Mean square error can again be used: 𝑖 𝒙𝑖𝑇 𝜷 − 𝑦𝑖

2/𝑛

28

Page 29: CS6220: Data Mining Techniques - Computer Science

AIC & BIC*

•AIC and BIC can be used to test the quality of statistical models

•AIC (Akaike information criterion)

• 𝐴𝐼𝐶 = 2𝑘 − 2ln( 𝐿),

• where k is the number of parameters in the model and 𝐿 is the likelihood under the estimated parameter

•BIC (Bayesian Information criterion)

• B𝐼𝐶 = 𝑘𝑙𝑛(𝑛) − 2ln( 𝐿),

• Where n is the number of objects29

Page 30: CS6220: Data Mining Techniques - Computer Science

Stepwise Feature Selection

•Avoid brute-force selection

• 2𝑝

• Forward selection• Starting with the best single feature

• Always add the feature that improves the performance best

• Stop if no feature will further improve the performance

• Backward elimination• Start with the full model

• Always remove the feature that results in the best performance enhancement

• Stop if removing any feature will get worse performance

30

Page 31: CS6220: Data Mining Techniques - Computer Science

Matrix Data: Prediction

•Matrix Data

•Linear Regression Model

•Model Evaluation and Selection

•Summary

31

Page 32: CS6220: Data Mining Techniques - Computer Science

Summary

•What is matrix data?• Attribute types

• Linear regression• OLS

• Probabilistic interpretation

•Model Evaluation and Selection• Bias-Variance Trade-off

• Mean square error

• Cross-validation, AIC, BIC, step-wise feature selection

32