데이터 과학 입문 5장

17
Doing Data Science ch.5 로지스틱 회귀 cecil

Upload: hyeonseok-choi

Post on 30-Jul-2015

101 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: 데이터 과학 입문 5장

Doing����������� ������������������  Data����������� ������������������  Science����������� ������������������  ch.5����������� ������������������  로지스틱����������� ������������������  회귀

cecil

Page 2: 데이터 과학 입문 5장

이����������� ������������������  장에서는?

분류기를����������� ������������������  선택하는����������� ������������������  과정에����������� ������������������  초점을����������� ������������������  맞추어����������� ������������������  

로지스틱����������� ������������������  회귀를����������� ������������������  이용한����������� ������������������  분류를����������� ������������������  설명

Page 3: 데이터 과학 입문 5장

데이터����������� ������������������  포인트를����������� ������������������  유한����������� ������������������  개의����������� ������������������  분류����������� ������������������  집합,����������� ������������������  

또는����������� ������������������  ����������� ������������������  ����������� ������������������  

분류명이나����������� ������������������  분류명에����������� ������������������  속할����������� ������������������  확률����������� ������������������  값에����������� ������������������  사상하는����������� ������������������  것

분류란?����������� ������������������  (Classifiers)����������� ������������������  

Page 4: 데이터 과학 입문 5장

질문 답변

이����������� ������������������  광고를����������� ������������������  누군가가����������� ������������������  클릭할����������� ������������������  것인가? 0����������� ������������������  또는����������� ������������������  1(예,����������� ������������������  아니오)

이것은����������� ������������������  무슨����������� ������������������  숫지인가? 0,����������� ������������������  1,����������� ������������������  2����������� ������������������  …⋯

이����������� ������������������  기사는����������� ������������������  어떤����������� ������������������  내용인가? 스포츠

이것은����������� ������������������  스팸인가? 0����������� ������������������  또는����������� ������������������  1

이것은����������� ������������������  두통����������� ������������������  약인가? 0����������� ������������������  또는����������� ������������������  1

언제����������� ������������������  분류����������� ������������������  작업을����������� ������������������  하는가?

이����������� ������������������  장에서는����������� ������������������  0과����������� ������������������  1에����������� ������������������  대해서만����������� ������������������  다룸.

Page 5: 데이터 과학 입문 5장

분류와����������� ������������������  관련하여����������� ������������������  생각해����������� ������������������  볼����������� ������������������  것들

1. 어떤����������� ������������������  분류기를����������� ������������������  사용할����������� ������������������  것인가?����������� ������������������  

2. 어떤����������� ������������������  최적화����������� ������������������  방법을����������� ������������������  선택할����������� ������������������  것인가?����������� ������������������  

3. 어떤����������� ������������������  손실����������� ������������������  함수를����������� ������������������  최소화����������� ������������������  할����������� ������������������  것인가?����������� ������������������  

4. 데이터에서����������� ������������������  어떤����������� ������������������  특징들을����������� ������������������  추출����������� ������������������  할����������� ������������������  것인가?����������� ������������������  

5. 어떤����������� ������������������  척도를����������� ������������������  사용할����������� ������������������  것인가?

Page 6: 데이터 과학 입문 5장

분류기����������� ������������������  선택과����������� ������������������  관련된����������� ������������������  제약사항

1. 실행����������� ������������������  시간����������� ������������������  •실제로����������� ������������������  의사����������� ������������������  결정을����������� ������������������  하기����������� ������������������  위해����������� ������������������  모형을����������� ������������������  사용하는����������� ������������������  시간����������� ������������������  

•그외����������� ������������������  시간)����������� ������������������  모형을����������� ������������������  업데이트����������� ������������������  하는데����������� ������������������  시간����������� ������������������  

2. 데이터����������� ������������������  과학자의����������� ������������������  알고리즘에����������� ������������������  대한����������� ������������������  이해����������� ������������������  

3. 해석����������� ������������������  가능성����������� ������������������  •비즈니스를����������� ������������������  위해����������� ������������������  모형이����������� ������������������  해석����������� ������������������  가능해야����������� ������������������  함����������� ������������������  

4. 확장성����������� ������������������  •학습시간,����������� ������������������  평가����������� ������������������  시간,����������� ������������������  모형의����������� ������������������  저장����������� ������������������  공간

Page 7: 데이터 과학 입문 5장

M6D����������� ������������������  로지스틱����������� ������������������  회귀����������� ������������������  사례����������� ������������������  연구

1. 과제:����������� ������������������  사용자����������� ������������������  수준에서의����������� ������������������  구매����������� ������������������  전환����������� ������������������  예측����������� ������������������  

•언제����������� ������������������  누가����������� ������������������  클릭할����������� ������������������  것인지를����������� ������������������  예상하는����������� ������������������  과제����������� ������������������  

2. 분류기로����������� ������������������  로지스틱����������� ������������������  회귀를����������� ������������������  선택����������� ������������������  

•확장성이����������� ������������������  높고����������� ������������������  클릭����������� ������������������  여부와����������� ������������������  같은����������� ������������������  이진����������� ������������������  결과를

Page 8: 데이터 과학 입문 5장

클릭����������� ������������������  모형����������� ������������������  설계

1. URL을����������� ������������������  무작위����������� ������������������  문자열로����������� ������������������  해시����������� ������������������  

2. 사용자들에����������� ������������������  대한����������� ������������������  정보를����������� ������������������  축척하고,����������� ������������������  벡터로����������� ������������������  만들어����������� ������������������  보관����������� ������������������  

3. Ex)����������� ������������������  u����������� ������������������  =����������� ������������������  <&ltfxyz,����������� ������������������  123,����������� ������������������  sdqwe,����������� ������������������  13ms&gtg>����������� ������������������  

4. 데이터����������� ������������������  행렬����������� ������������������  

•열:����������� ������������������  전체����������� ������������������  사이트,����������� ������������������  행:����������� ������������������  전체����������� ������������������  사용자����������� ������������������  

•방문한����������� ������������������  사이트의����������� ������������������  경우����������� ������������������  1로����������� ������������������  표시.����������� ������������������  

•훈련����������� ������������������  데이트를����������� ������������������  위해����������� ������������������  분류명����������� ������������������  변수����������� ������������������  추가(클릭/클린����������� ������������������  안함)

Page 9: 데이터 과학 입문 5장

이전����������� ������������������  장과의����������� ������������������  비교

1. 분류의����������� ������������������  관점����������� ������������������  

•나이브����������� ������������������  베이즈를����������� ������������������  사용한����������� ������������������  스팸����������� ������������������  분류기와����������� ������������������  유사����������� ������������������  

2. 선형����������� ������������������  회기와의����������� ������������������  차이점����������� ������������������  

•선형����������� ������������������  회귀:����������� ������������������  실제����������� ������������������  값을����������� ������������������  예측����������� ������������������  

•로지스틱����������� ������������������  회귀:����������� ������������������  실제����������� ������������������  값에����������� ������������������  대한����������� ������������������  확률을����������� ������������������  출력

Page 10: 데이터 과학 입문 5장

수학적����������� ������������������  배경

1. 로지스틱����������� ������������������  회귀는����������� ������������������  결과가����������� ������������������  확률����������� ������������������  값(0����������� ������������������  ~����������� ������������������  1����������� ������������������  사이����������� ������������������  값)����������� ������������������  

•예측����������� ������������������  값을����������� ������������������  0����������� ������������������  ~����������� ������������������  1����������� ������������������  사이����������� ������������������  값으로����������� ������������������  표현할����������� ������������������  방법이����������� ������������������  필요����������� ������������������  

2. 역로짓함수:����������� ������������������  실수����������� ������������������  값을����������� ������������������  [0,����������� ������������������  1]내로����������� ������������������  한정된����������� ������������������  단일����������� ������������������  값으로����������� ������������������  변환)

The Underlying MathSo far we’ve seen that the beauty of logistic regression is it outputsvalues bounded by 0 and 1; hence they can be directly interpreted asprobabilities. Let’s get into the math behind it a bit. You want a functionthat takes the data and transforms it into a single value bounded insidethe closed interval 0,1 . For an example of a function bounded be‐tween 0 and 1, consider the inverse-logit function shown in Figure 5-2.

P t = logit−1 t ≡ 11+e−t = et

1+et

Figure 5-2. The inverse-logit function

Logit Versus Inverse-logitThe logit function takes x values in the range 0,1 and transformsthem to y values along the entire real line:

logit p = log p1− p = log p − log 1− p

The inverse-logit does the reverse, and takes x values along the realline and tranforms them to y values in the range 0,1 .

Note when t is large, e−t is tiny so the denominator is close to 1 andthe overall value is close to 1. Similarly when t is small, e−t is large so

120 | Chapter 5: Logistic Regression

www.it-ebooks.info

The Underlying MathSo far we’ve seen that the beauty of logistic regression is it outputsvalues bounded by 0 and 1; hence they can be directly interpreted asprobabilities. Let’s get into the math behind it a bit. You want a functionthat takes the data and transforms it into a single value bounded insidethe closed interval 0,1 . For an example of a function bounded be‐tween 0 and 1, consider the inverse-logit function shown in Figure 5-2.

P t = logit−1 t ≡ 11+e−t = et

1+et

Figure 5-2. The inverse-logit function

Logit Versus Inverse-logitThe logit function takes x values in the range 0,1 and transformsthem to y values along the entire real line:

logit p = log p1− p = log p − log 1− p

The inverse-logit does the reverse, and takes x values along the realline and tranforms them to y values in the range 0,1 .

Note when t is large, e−t is tiny so the denominator is close to 1 andthe overall value is close to 1. Similarly when t is small, e−t is large so

120 | Chapter 5: Logistic Regression

www.it-ebooks.info

The Underlying MathSo far we’ve seen that the beauty of logistic regression is it outputsvalues bounded by 0 and 1; hence they can be directly interpreted asprobabilities. Let’s get into the math behind it a bit. You want a functionthat takes the data and transforms it into a single value bounded insidethe closed interval 0,1 . For an example of a function bounded be‐tween 0 and 1, consider the inverse-logit function shown in Figure 5-2.

P t = logit−1 t ≡ 11+e−t = et

1+et

Figure 5-2. The inverse-logit function

Logit Versus Inverse-logitThe logit function takes x values in the range 0,1 and transformsthem to y values along the entire real line:

logit p = log p1− p = log p − log 1− p

The inverse-logit does the reverse, and takes x values along the realline and tranforms them to y values in the range 0,1 .

Note when t is large, e−t is tiny so the denominator is close to 1 andthe overall value is close to 1. Similarly when t is small, e−t is large so

120 | Chapter 5: Logistic Regression

www.it-ebooks.info

로짓함수:����������� ������������������  [0,1]����������� ������������������  사이����������� ������������������  값을����������� ������������������  전체����������� ������������������  실수����������� ������������������  범위로����������� ������������������  맵핑

Page 11: 데이터 과학 입문 5장

데이터����������� ������������������  모형화the denominator is large, which makes the function close to zero. Sothat’s the inverse-logit function, which you’ll use to begin deriving alogistic regression model. In order to model the data, you need to workwith a slightly more general function that expresses the relationshipbetween the data and a probability of a click. Start by defining:

P ci xi = logit−1 α+ βτxici * 1− logit−1 α+ βτxi

1−ci

Here ci is the labels or classes (clicked or not), and xi is the vector offeatures for user i. Observe that ci can only be 1 or 0, which means thatif ci = 1, the second term cancels out and you have:

P ci = 1 xi = 1

1+e− α+βτxi= logit−1 α+ βτxi

And similarly, if ci = 0, the first term cancels out and you have:

P ci = 0 xi = 1− logit−1 α+ βτxi

To make this a linear model in the outcomes ci, take the log of the oddsratio:

log P ci = 1 xi / 1−P ci = 1 xi = α+ βτxi .

Which can also be written as:

logit P ci = 1 xi = α+ βτxi .

If it feels to you that we went in a bit of a circle here (this last equationwas also implied by earlier equations), it’s because we did. The purposeof this was to show you how to go back and forth between the prob‐abilities and the linearity.

So the logit of the probability that user i clicks on the shoe ad is beingmodeled as a linear function of the features, which were the URLs thatuser i visited. This model is called the logistic regression model.

The parameter α is what we call the base rate, or the unconditionalprobability of “1” or “click” knowing nothing more about a given user’s

M6D Logistic Regression Case Study | 121

www.it-ebooks.info

클릭����������� ������������������  및����������� ������������������  클릭����������� ������������������  안함에����������� ������������������  대한����������� ������������������  확률����������� ������������������  질량����������� ������������������  함수

the denominator is large, which makes the function close to zero. Sothat’s the inverse-logit function, which you’ll use to begin deriving alogistic regression model. In order to model the data, you need to workwith a slightly more general function that expresses the relationshipbetween the data and a probability of a click. Start by defining:

P ci xi = logit−1 α+ βτxici * 1− logit−1 α+ βτxi

1−ci

Here ci is the labels or classes (clicked or not), and xi is the vector offeatures for user i. Observe that ci can only be 1 or 0, which means thatif ci = 1, the second term cancels out and you have:

P ci = 1 xi = 1

1+e− α+βτxi= logit−1 α+ βτxi

And similarly, if ci = 0, the first term cancels out and you have:

P ci = 0 xi = 1− logit−1 α+ βτxi

To make this a linear model in the outcomes ci, take the log of the oddsratio:

log P ci = 1 xi / 1−P ci = 1 xi = α+ βτxi .

Which can also be written as:

logit P ci = 1 xi = α+ βτxi .

If it feels to you that we went in a bit of a circle here (this last equationwas also implied by earlier equations), it’s because we did. The purposeof this was to show you how to go back and forth between the prob‐abilities and the linearity.

So the logit of the probability that user i clicks on the shoe ad is beingmodeled as a linear function of the features, which were the URLs thatuser i visited. This model is called the logistic regression model.

The parameter α is what we call the base rate, or the unconditionalprobability of “1” or “click” knowing nothing more about a given user’s

M6D Logistic Regression Case Study | 121

www.it-ebooks.info

the denominator is large, which makes the function close to zero. Sothat’s the inverse-logit function, which you’ll use to begin deriving alogistic regression model. In order to model the data, you need to workwith a slightly more general function that expresses the relationshipbetween the data and a probability of a click. Start by defining:

P ci xi = logit−1 α+ βτxici * 1− logit−1 α+ βτxi

1−ci

Here ci is the labels or classes (clicked or not), and xi is the vector offeatures for user i. Observe that ci can only be 1 or 0, which means thatif ci = 1, the second term cancels out and you have:

P ci = 1 xi = 1

1+e− α+βτxi= logit−1 α+ βτxi

And similarly, if ci = 0, the first term cancels out and you have:

P ci = 0 xi = 1− logit−1 α+ βτxi

To make this a linear model in the outcomes ci, take the log of the oddsratio:

log P ci = 1 xi / 1−P ci = 1 xi = α+ βτxi .

Which can also be written as:

logit P ci = 1 xi = α+ βτxi .

If it feels to you that we went in a bit of a circle here (this last equationwas also implied by earlier equations), it’s because we did. The purposeof this was to show you how to go back and forth between the prob‐abilities and the linearity.

So the logit of the probability that user i clicks on the shoe ad is beingmodeled as a linear function of the features, which were the URLs thatuser i visited. This model is called the logistic regression model.

The parameter α is what we call the base rate, or the unconditionalprobability of “1” or “click” knowing nothing more about a given user’s

M6D Logistic Regression Case Study | 121

www.it-ebooks.info

the denominator is large, which makes the function close to zero. Sothat’s the inverse-logit function, which you’ll use to begin deriving alogistic regression model. In order to model the data, you need to workwith a slightly more general function that expresses the relationshipbetween the data and a probability of a click. Start by defining:

P ci xi = logit−1 α+ βτxici * 1− logit−1 α+ βτxi

1−ci

Here ci is the labels or classes (clicked or not), and xi is the vector offeatures for user i. Observe that ci can only be 1 or 0, which means thatif ci = 1, the second term cancels out and you have:

P ci = 1 xi = 1

1+e− α+βτxi= logit−1 α+ βτxi

And similarly, if ci = 0, the first term cancels out and you have:

P ci = 0 xi = 1− logit−1 α+ βτxi

To make this a linear model in the outcomes ci, take the log of the oddsratio:

log P ci = 1 xi / 1−P ci = 1 xi = α+ βτxi .

Which can also be written as:

logit P ci = 1 xi = α+ βτxi .

If it feels to you that we went in a bit of a circle here (this last equationwas also implied by earlier equations), it’s because we did. The purposeof this was to show you how to go back and forth between the prob‐abilities and the linearity.

So the logit of the probability that user i clicks on the shoe ad is beingmodeled as a linear function of the features, which were the URLs thatuser i visited. This model is called the logistic regression model.

The parameter α is what we call the base rate, or the unconditionalprobability of “1” or “click” knowing nothing more about a given user’s

M6D Logistic Regression Case Study | 121

www.it-ebooks.info

the denominator is large, which makes the function close to zero. Sothat’s the inverse-logit function, which you’ll use to begin deriving alogistic regression model. In order to model the data, you need to workwith a slightly more general function that expresses the relationshipbetween the data and a probability of a click. Start by defining:

P ci xi = logit−1 α+ βτxici * 1− logit−1 α+ βτxi

1−ci

Here ci is the labels or classes (clicked or not), and xi is the vector offeatures for user i. Observe that ci can only be 1 or 0, which means thatif ci = 1, the second term cancels out and you have:

P ci = 1 xi = 1

1+e− α+βτxi= logit−1 α+ βτxi

And similarly, if ci = 0, the first term cancels out and you have:

P ci = 0 xi = 1− logit−1 α+ βτxi

To make this a linear model in the outcomes ci, take the log of the oddsratio:

log P ci = 1 xi / 1−P ci = 1 xi = α+ βτxi .

Which can also be written as:

logit P ci = 1 xi = α+ βτxi .

If it feels to you that we went in a bit of a circle here (this last equationwas also implied by earlier equations), it’s because we did. The purposeof this was to show you how to go back and forth between the prob‐abilities and the linearity.

So the logit of the probability that user i clicks on the shoe ad is beingmodeled as a linear function of the features, which were the URLs thatuser i visited. This model is called the logistic regression model.

The parameter α is what we call the base rate, or the unconditionalprobability of “1” or “click” knowing nothing more about a given user’s

M6D Logistic Regression Case Study | 121

www.it-ebooks.info

i가����������� ������������������  클릭할����������� ������������������  확률의����������� ������������������  로짓은����������� ������������������  특징들이����������� ������������������  선형����������� ������������������  함수로����������� ������������������  표현

Page 12: 데이터 과학 입문 5장

로지스틱����������� ������������������  회귀����������� ������������������  모형

the denominator is large, which makes the function close to zero. Sothat’s the inverse-logit function, which you’ll use to begin deriving alogistic regression model. In order to model the data, you need to workwith a slightly more general function that expresses the relationshipbetween the data and a probability of a click. Start by defining:

P ci xi = logit−1 α+ βτxici * 1− logit−1 α+ βτxi

1−ci

Here ci is the labels or classes (clicked or not), and xi is the vector offeatures for user i. Observe that ci can only be 1 or 0, which means thatif ci = 1, the second term cancels out and you have:

P ci = 1 xi = 1

1+e− α+βτxi= logit−1 α+ βτxi

And similarly, if ci = 0, the first term cancels out and you have:

P ci = 0 xi = 1− logit−1 α+ βτxi

To make this a linear model in the outcomes ci, take the log of the oddsratio:

log P ci = 1 xi / 1−P ci = 1 xi = α+ βτxi .

Which can also be written as:

logit P ci = 1 xi = α+ βτxi .

If it feels to you that we went in a bit of a circle here (this last equationwas also implied by earlier equations), it’s because we did. The purposeof this was to show you how to go back and forth between the prob‐abilities and the linearity.

So the logit of the probability that user i clicks on the shoe ad is beingmodeled as a linear function of the features, which were the URLs thatuser i visited. This model is called the logistic regression model.

The parameter α is what we call the base rate, or the unconditionalprobability of “1” or “click” knowing nothing more about a given user’s

M6D Logistic Regression Case Study | 121

www.it-ebooks.info

1.����������� ������������������  모수����������� ������������������  알파:����������� ������������������  기저율,����������� ������������������  ����������� ������������������  •어떤����������� ������������������  사용자가����������� ������������������  벡터����������� ������������������  x에����������� ������������������  대해서����������� ������������������  알려진����������� ������������������  바가����������� ������������������  없을때����������� ������������������  ‘1’일����������� ������������������  확률����������� ������������������  

•기저율외����������� ������������������  특별한����������� ������������������  정보가����������� ������������������  없다면����������� ������������������  알파만����������� ������������������  평균����������� ������������������  예측은����������� ������������������  알파로����������� ������������������  실행����������� ������������������  

3.����������� ������������������  베타:����������� ������������������  로짓함수의����������� ������������������  기울기����������� ������������������  •일반적으로����������� ������������������  각����������� ������������������  데이터����������� ������������������  포인트에서의����������� ������������������  특징의����������� ������������������  개수����������� ������������������  만큼의����������� ������������������  차원을����������� ������������������  가지는����������� ������������������  벡터����������� ������������������  

•벡터����������� ������������������  베타는����������� ������������������  어떤����������� ������������������  특징이����������� ������������������  광고를����������� ������������������  클릭할����������� ������������������  가능도를����������� ������������������  증가����������� ������������������  또는����������� ������������������  감소����������� ������������������  시키는����������� ������������������  정도를����������� ������������������  결정

feature vector xi. In the case of measuring the likelihood of an averageuser clicking on an ad, the base rate would correspond to the click-through rate, i.e., the tendency over all users to click on ads. This istypically on the order of 1%.

If you had no information about your specific situation except the baserate, the average prediction would be given by just α:

P ci = 1 = 11+e−α

The variable β defines the slope of the logit function. Note that ingeneral it’s a vector that is as long as the number of features you areusing for each data point. The vector β determines the extent to whichcertain features are markers for increased or decreased likelihood toclick on an ad.

Estimating α and βYour immediate modeling goal is to use the training data to find thebest choices for α and β . In general you want to solve this with max‐imum likelihood estimation and use a convex optimization algorithmbecause the likelihood function is convex; you can’t just use derivativesand vector calculus like you did with linear regression because it’s acomplicated function of your data, and in particular there is no closed-form solution.

Denote by Θ the pair α,β . The likelihood function L is defined by:

L Θ X1,X2,⋯,Xn = P X Θ = P X1 Θ ·⋯ ·P Xn Θ

where you are assuming the data points Xi are independent, wherei = 1, . . . ,n represent your n users. This independence assumption cor‐responds to saying that the click behavior of any given user doesn’taffect the click behavior of all the other users—in this case, “click be‐havior” means “probability of clicking.” It’s a relatively safe assumptionat a given point in time, but not forever. (Remember the independenceassumption is what allows you to express the likelihood function asthe product of the densities for each of the n observations.)

You then search for the parameters that maximize the likelihood, hav‐ing observed your data:

122 | Chapter 5: Logistic Regression

www.it-ebooks.info

Page 13: 데이터 과학 입문 5장

알파����������� ������������������  및����������� ������������������  베타의����������� ������������������  추정

1.����������� ������������������  최적의����������� ������������������  알파와����������� ������������������  베타����������� ������������������  값을����������� ������������������  선택하기����������� ������������������  위해����������� ������������������  데이터를����������� ������������������  훈련����������� ������������������  시키는����������� ������������������  

것이����������� ������������������  모형화에서의����������� ������������������  당면한����������� ������������������  목표����������� ������������������  

2.����������� ������������������  최대����������� ������������������  가능도����������� ������������������  방법����������� ������������������  •가능도:����������� ������������������  알려진����������� ������������������  결과(관측표본)에����������� ������������������  기초하여����������� ������������������  미지의����������� ������������������  매배����������� ������������������  변수(모수)의����������� ������������������  추정

에����������� ������������������  대한����������� ������������������  척도����������� ������������������  

•가능도����������� ������������������  함수:����������� ������������������  미지의����������� ������������������  모수����������� ������������������  세타라는����������� ������������������  변수에����������� ������������������  의존하는����������� ������������������  함수����������� ������������������  

•최대����������� ������������������  가능도����������� ������������������  방법:����������� ������������������  확률����������� ������������������  변수에서����������� ������������������  표집한����������� ������������������  값을����������� ������������������  토대로����������� ������������������  그����������� ������������������  확률����������� ������������������  변수의����������� ������������������  모수를����������� ������������������  

구하는����������� ������������������  방법

feature vector xi. In the case of measuring the likelihood of an averageuser clicking on an ad, the base rate would correspond to the click-through rate, i.e., the tendency over all users to click on ads. This istypically on the order of 1%.

If you had no information about your specific situation except the baserate, the average prediction would be given by just α:

P ci = 1 = 11+e−α

The variable β defines the slope of the logit function. Note that ingeneral it’s a vector that is as long as the number of features you areusing for each data point. The vector β determines the extent to whichcertain features are markers for increased or decreased likelihood toclick on an ad.

Estimating α and βYour immediate modeling goal is to use the training data to find thebest choices for α and β . In general you want to solve this with max‐imum likelihood estimation and use a convex optimization algorithmbecause the likelihood function is convex; you can’t just use derivativesand vector calculus like you did with linear regression because it’s acomplicated function of your data, and in particular there is no closed-form solution.

Denote by Θ the pair α,β . The likelihood function L is defined by:

L Θ X1,X2,⋯,Xn = P X Θ = P X1 Θ ·⋯ ·P Xn Θ

where you are assuming the data points Xi are independent, wherei = 1, . . . ,n represent your n users. This independence assumption cor‐responds to saying that the click behavior of any given user doesn’taffect the click behavior of all the other users—in this case, “click be‐havior” means “probability of clicking.” It’s a relatively safe assumptionat a given point in time, but not forever. (Remember the independenceassumption is what allows you to express the likelihood function asthe product of the densities for each of the n observations.)

You then search for the parameters that maximize the likelihood, hav‐ing observed your data:

122 | Chapter 5: Logistic Regression

www.it-ebooks.info

Page 14: 데이터 과학 입문 5장

가능도를����������� ������������������  최대화����������� ������������������  하기����������� ������������������  위한����������� ������������������  방법

1. 뉴턴의����������� ������������������  방법(미적분학)����������� ������������������  

•전역����������� ������������������  최댓값을����������� ������������������  찾는����������� ������������������  수치적����������� ������������������  기법����������� ������������������  

2. 확률적����������� ������������������  경사����������� ������������������  감소법����������� ������������������  

•한번에����������� ������������������  하나의����������� ������������������  관측값을����������� ������������������  사용하여����������� ������������������  경사를����������� ������������������  근사하는����������� ������������������  법

Page 15: 데이터 과학 입문 5장

평����������� ������������������  가

1. 순위를����������� ������������������  매기는����������� ������������������  상황을����������� ������������������  로지스틱����������� ������������������  회귀로����������� ������������������  모형화����������� ������������������  

•ROC����������� ������������������  곡선����������� ������������������  아래����������� ������������������  면적����������� ������������������  

•누적향상도����������� ������������������  곡선����������� ������������������  아래����������� ������������������  면적����������� ������������������  

2. 분류����������� ������������������  목적으로����������� ������������������  로지스틱����������� ������������������  회귀를����������� ������������������  사용하는����������� ������������������  경우����������� ������������������  

•향상도,����������� ������������������  정확도,����������� ������������������  정밀도,����������� ������������������  재현율,����������� ������������������  F-점수����������� ������������������  

3. 확률����������� ������������������  밀도����������� ������������������  추정����������� ������������������  

•평균����������� ������������������  제곱����������� ������������������  오차,����������� ������������������  평균����������� ������������������  제곱����������� ������������������  오차의����������� ������������������  제곱근,����������� ������������������  평균����������� ������������������  절대����������� ������������������  오차

Page 16: 데이터 과학 입문 5장

Q&A

Page 17: 데이터 과학 입문 5장

References• Rachel����������� ������������������  Schutt,����������� ������������������  Cathy����������� ������������������  O’Neil,����������� ������������������  데이터����������� ������������������  과학����������� ������������������  입문(윤영민,����������� ������������������  허선,����������� ������������������  

전희주,����������� ������������������  김정일,����������� ������������������  류자현����������� ������������������  옮김).����������� ������������������  서울시����������� ������������������  마포구:����������� ������������������  한빛����������� ������������������  미디어,����������� ������������������  2014����������� ������������������  

• https://en.wikipedia.org/wiki/Logistic_regression����������� ������������������  

• https://ko.wikipedia.org/wiki/%EB%A1%9C%EC%A7%80%EC%8A%A4%ED%8B%B1_%ED%9A%8C%EA%B7%80����������� ������������������  

• https://ko.wikipedia.org/wiki/%EA%B0%80%EB%8A%A5%EB%8F%84