Docsity

Logistic Regression for Classification: Linear Models and Maximum Entropy, Exams of Computer Science

Toggle sidebar
bg1
Machine Learning (CS 5350/CS 6350) 18 Jan 2006
Linear models for classification
We’ve talked about regressing on R... what about {−1,+1}? Consider our old example, augmented with
some new features.
Length ≥155 Width ≥90 Cool Design Type
1 0 1 Ski
1 0 0 Ski
11 0 Ski
10 0 Ski
10 1 Ski
1 1 0 Ski
1 0 0 Ski
0 0 0 Ski
1 1 1 Snowboard
1 1 1 Snowboard
0 1 1 Snowboard
0 1 1 Snowboard
0 0 0 Snowboard
0 1 0 Snowboard
0 0 1 Snowboard
01 1 Snowboard
Idea: learn a predictor that is largely positive for one class and largely negative for another.
Sigmoid function:
σ(x) = exp[x/2]
exp[x/2] + exp[−x/2]
=1
1 + exp[−x]
Inverse is the logistic:
σ−1(y) = log y
1−y
Specify a probability distribution on yconditioned on x:
pθ(y|x) = σ(yθ>x) = 1
1 + exp[−yθ>x]
This is the logistic regression model.
No closed-form solution exists; compute log likelihood:
`(θ) = log Y
n
pθ(yn|xn)
1
pf3
pf4

Partial preview of the text

Download Logistic Regression for Classification: Linear Models and Maximum Entropy and more Exams Computer Science in PDF only on Docsity!

Machine Learning (CS 5350/CS 6350) 18 Jan 2006

Linear models for classification

We’ve talked about regressing on R... what about {− 1 , +1}? Consider our old example, augmented with some new features.

Length ≥ 155 Width ≥ 90 Cool Design Type 1 0 1 Ski 1 0 0 Ski 1 1 0 Ski 1 0 0 Ski 1 0 1 Ski 1 1 0 Ski 1 0 0 Ski 0 0 0 Ski 1 1 1 Snowboard 1 1 1 Snowboard 0 1 1 Snowboard 0 1 1 Snowboard 0 0 0 Snowboard 0 1 0 Snowboard 0 0 1 Snowboard 0 1 1 Snowboard

Idea: learn a predictor that is largely positive for one class and largely negative for another.

Sigmoid function:

σ(x) =

exp[x/2] exp[x/2] + exp[−x/2]

=

1 + exp[−x]

Inverse is the logistic:

σ−^1 (y) = log

y 1 − y

Specify a probability distribution on y conditioned on x:

pθ (y | x) = σ(yθ>x) =

1 + exp[−yθ>x]

This is the logistic regression model.

No closed-form solution exists; compute log likelihood:

`(θ) = log

n

pθ (yn | xn)

n

log

1 + exp[−ynθ>xn]

= −

n

log

1 + exp[−ynθ>xn]

Now, compute the gradient.

∇θ ` = −

n

1 + exp[−ynθ>xn]

exp−ynθ>xn

n

1 + exp[ynθ>xn] ynxn

And we can do gradient descent.

This is a linear model because the output (±1) is a (thresholded) linear function of the input. For linear functions, we can draw the decision boundary as a linear function:

−4 −2 0 2 4 6 8

−

−

−

−

0

2

4

Find set of x for which θ>x = 0 and this is the decision boundary, which will be linear.

For multiclass problems, replace logistic with soft-max. For each of the K classes, let θk,: be a weight vector. Then, set:

pθ (y | x) =

exp[θy >x] ∑ k exp[θk>x]

For a two class problem, this reduces to the logistic (with a small adjustment of parameters). Usually fix θ 0 ,: = 0 for identifiability.

Compute log-likelihood and gradient:

Exercise: verify that there exist parameters π, θ for the naive Bayes model that mimick the logistic regression behavior (and vice-versa).

Change of pace...

Making things work:

  1. Scale/translation of features interacts with regularization. Can “whiten” (or bound) data to fix this.
  2. Output of regression can also be centered. (Reduces need for “bias feature.”)
  3. Some interactions are exponential: take log of features.

Doing good experiments:

  1. Often need to choose “hyperparameters.” Can use k-fold cross-validation, LOO xval or use a develop- ment/validation set. Typically k = 10.
  2. Performance on development data better indicator of performance on test.
  3. Never look at your development/test data. I mean it: never.
  4. When breaking data into train/dev/test, be careful.