SlideShare a Scribd company logo
1 of 33
Download to read offline
Logistic Regression
MinHyeok Kim
NHN NEXT
SW Maestro 5th
Logistic Regression
입력변수 x에 대하여 출력변수 Y가 1이 될 확률 추정
• 장점 : 계산비용이 적고, 구현하기 쉬우며, 결과해석을 위한 지식 표현이 쉽다
• 단점 : 언더피팅(underfitting) 경향이 있어 정확도가 낮게 나올수도 있다.
Logistic Regression?
입력변수 x에 대하여 출력변수 Y가 1이 될 확률 추정
• 장점 : 계산비용이 적고, 구현하기 쉬우며, 결과해석을 위한 지식 표현이 쉽다
• 단점 : 언더피팅(underfitting) 경향이 있어 정확도가 낮게 나올수도 있다.
• 데이터가 표시된 좌표평면을 가로지르는 최적선(best-fit line)을 구하는 것
• 회귀는 가장 알맞은 매개변수의 집합을 찾으려는 양상을 나타낸다
• 종속변수가 비선형일 경우 선형 모형을 적용하기 어렵다
• 비선형 -> Logistic Regression!
Regression Analysis
• 연령, 자동차 소유 유무, 연간소득 등과 같은 특성이 개인신용분량 여부에 어떠한 영향을 미치는가?

• 유권자의 연령, 성별, 거주지역, 학력 등이 선호하는 후보선택에 어떠한 영향을 미치는가?

• 흡연 유무, 주량, 직업, 비만 정도, 키와 같은 특성이 특정한 질병발생에 어떠한 영향을 미치는가?

• 선택대상이 되는 상표들에 대한 평가와 응답자의 특성이 선호상표 선택에 어떠한 영향을 미치는가?
Definition
Logistic Function
An explanation of a Logistic Regression begins with
an explanation of the “Logistic Function”
Logistic Regression!
== odds :일어날 확률 / 안 일어날 확률
회귀계수에 따라 특정 집단에 속할 확률이 달라짐
이 계수의 해석으로 어떤 변수가 확률을 높이거나 낮추는 요인인지 알수있게함
If there are multiple explanatory variables, the above expression
can be revised to
Multiple Logistic Regression!
How it works?
in “ML in Action”
Optimization Algorithm
• 가장 알맞은 매개변수를 찾기위해 최적화 알고리즘을 사용한다
• ML in Action에서는 GD, SGD를 이용
Gradient Descent
• 기울기가 낮은(높은)쪽으로 계속 이동시켜서 극값에 이를때까지 반복
• 모든 차원과 모든 공간에서의 적용에서도 사용가능(무한까지도)
• 극값 이동에 대해 매우 많은 단계를 거쳐야하며, 함수의 곡률에 따라 거의 같은 위치에서 시작했음에도
불구하고 완전히 다른 결과로 이어질수도 있다
This Procedure is also known as gradient ascent
Stochastic Gradient Descent
• 너무 많은 연산을 필요로하는 기존의 알고리즘(GD)을 보완
• 한번에 단 하나의 사례를 사용하여 가중치 계산
• Online Learning Algorithm, Not batch processing
미분 가능 : 변수 x의 값의 변화량에 대한 함수 f(x)의 변화량 비가 한없이 일정한 값에 가까워지는것
Activation Function
(Sigmoid function)
• 비선형적인 값들을 선형적으로 변환해준다
• 어떤 값이 시그모이드 함수를 거치면 미분 가능한 형태로 변환된다
미분 가능 : 변수 x의 값의 변화량에 대한 함수 f(x)의 변화량 비가 한없이 일정한 값에 가까워지는것
Activation Function
(Sigmoid function)
• 비선형적인 값들을 선형적으로 변환해준다
• 어떤 값이 시그모이드 함수를 거치면 미분 가능한 형태로 변환된다
Hmm.. It’s similar to…
Let’s try using python!
using numpy(http://www.numpy.org/)
Case 1. Gradient Ascent
결과는 괜찮지만 데이터수가 많아진다면?
Case 2. Stochastic Gradient Ascent
Not Good… :(
알고리즘 개선
1. 불규칙적인 alpha 값
2. 임의 사례 선택
Real Case. Logistic Regression
http://archive.ics.uci.edu/ml/datasets/Horse+Colic
데이터를 정제할 필요가 있다 :(
1. 알수없는 값 = 0으로 처리
weights = weights + alpha * error dataMatrix[randIndex]
weights = weights (dataMatrix[i] = 0)
2. 분류 표시 누락 = 무시
대체하기 어렵다
Another case
Goal : to identify the various factors that
may influence admission into graduate school
rank : prestige of an applicant’s undergraduate alma mater
Data : http://www.ats.ucla.edu/stat/data/binary.csv
Rename because there is also the name of a method pandas DataFrame
“get_dummies” helps how categorical variables are represented
to prevent multicollinearity or the dummy variable trap,
“prestige_1” is our baseline and exclude it from our fit
add manually the intercept as constant and do a logistic regression
Thanks!

More Related Content

Viewers also liked

20160409 microsoft 세미나 머신러닝관련 발표자료
20160409 microsoft 세미나 머신러닝관련 발표자료20160409 microsoft 세미나 머신러닝관련 발표자료
20160409 microsoft 세미나 머신러닝관련 발표자료JungGeun Lee
 
파이콘 2017 그만퇴근합시다_이지호
파이콘 2017 그만퇴근합시다_이지호파이콘 2017 그만퇴근합시다_이지호
파이콘 2017 그만퇴근합시다_이지호Jiho Lee
 
Linear regression analysis
Linear regression analysisLinear regression analysis
Linear regression analysismothersafe
 
해커에게 전해들은 머신러닝 #4
해커에게 전해들은 머신러닝 #4해커에게 전해들은 머신러닝 #4
해커에게 전해들은 머신러닝 #4Haesun Park
 
인공지능 변호사 개발 1편 - Ai lawyer 개발을 위한 시도
인공지능 변호사 개발  1편 - Ai lawyer 개발을 위한 시도 인공지능 변호사 개발  1편 - Ai lawyer 개발을 위한 시도
인공지능 변호사 개발 1편 - Ai lawyer 개발을 위한 시도 jason min
 
4.representing data and engineering features
4.representing data and engineering features4.representing data and engineering features
4.representing data and engineering featuresHaesun Park
 
6.algorithm chains and piplines
6.algorithm chains and piplines6.algorithm chains and piplines
6.algorithm chains and piplinesHaesun Park
 
5.model evaluation and improvement
5.model evaluation and improvement5.model evaluation and improvement
5.model evaluation and improvementHaesun Park
 
해커에게 전해들은 머신러닝 #2
해커에게 전해들은 머신러닝 #2해커에게 전해들은 머신러닝 #2
해커에게 전해들은 머신러닝 #2Haesun Park
 
AlphaGo 알고리즘 요약
AlphaGo 알고리즘 요약AlphaGo 알고리즘 요약
AlphaGo 알고리즘 요약Jooyoul Lee
 
1.introduction(epoch#2)
1.introduction(epoch#2)1.introduction(epoch#2)
1.introduction(epoch#2)Haesun Park
 
1.Introduction to Python and TensorFlow
1.Introduction to Python and TensorFlow1.Introduction to Python and TensorFlow
1.Introduction to Python and TensorFlowHaesun Park
 
파이썬 생존 안내서 (자막)
파이썬 생존 안내서 (자막)파이썬 생존 안내서 (자막)
파이썬 생존 안내서 (자막)Heungsub Lee
 
EMOCON 2017 F/W - Deep Learning과 Keras 기초
EMOCON 2017 F/W - Deep Learning과 Keras 기초EMOCON 2017 F/W - Deep Learning과 Keras 기초
EMOCON 2017 F/W - Deep Learning과 Keras 기초Ashal aka JOKER
 
해커에게 전해들은 머신러닝 #1
해커에게 전해들은 머신러닝 #1해커에게 전해들은 머신러닝 #1
해커에게 전해들은 머신러닝 #1Haesun Park
 
2.supervised learning(epoch#2)-1
2.supervised learning(epoch#2)-12.supervised learning(epoch#2)-1
2.supervised learning(epoch#2)-1Haesun Park
 
Basic Understanding of the Deep
Basic Understanding of the DeepBasic Understanding of the Deep
Basic Understanding of the DeepMad Scientists
 
2.supervised learning(epoch#2)-2
2.supervised learning(epoch#2)-22.supervised learning(epoch#2)-2
2.supervised learning(epoch#2)-2Haesun Park
 
3.unsupervised learing
3.unsupervised learing3.unsupervised learing
3.unsupervised learingHaesun Park
 

Viewers also liked (20)

20160409 microsoft 세미나 머신러닝관련 발표자료
20160409 microsoft 세미나 머신러닝관련 발표자료20160409 microsoft 세미나 머신러닝관련 발표자료
20160409 microsoft 세미나 머신러닝관련 발표자료
 
파이콘 2017 그만퇴근합시다_이지호
파이콘 2017 그만퇴근합시다_이지호파이콘 2017 그만퇴근합시다_이지호
파이콘 2017 그만퇴근합시다_이지호
 
Linear regression analysis
Linear regression analysisLinear regression analysis
Linear regression analysis
 
Text summarization
Text summarizationText summarization
Text summarization
 
해커에게 전해들은 머신러닝 #4
해커에게 전해들은 머신러닝 #4해커에게 전해들은 머신러닝 #4
해커에게 전해들은 머신러닝 #4
 
인공지능 변호사 개발 1편 - Ai lawyer 개발을 위한 시도
인공지능 변호사 개발  1편 - Ai lawyer 개발을 위한 시도 인공지능 변호사 개발  1편 - Ai lawyer 개발을 위한 시도
인공지능 변호사 개발 1편 - Ai lawyer 개발을 위한 시도
 
4.representing data and engineering features
4.representing data and engineering features4.representing data and engineering features
4.representing data and engineering features
 
6.algorithm chains and piplines
6.algorithm chains and piplines6.algorithm chains and piplines
6.algorithm chains and piplines
 
5.model evaluation and improvement
5.model evaluation and improvement5.model evaluation and improvement
5.model evaluation and improvement
 
해커에게 전해들은 머신러닝 #2
해커에게 전해들은 머신러닝 #2해커에게 전해들은 머신러닝 #2
해커에게 전해들은 머신러닝 #2
 
AlphaGo 알고리즘 요약
AlphaGo 알고리즘 요약AlphaGo 알고리즘 요약
AlphaGo 알고리즘 요약
 
1.introduction(epoch#2)
1.introduction(epoch#2)1.introduction(epoch#2)
1.introduction(epoch#2)
 
1.Introduction to Python and TensorFlow
1.Introduction to Python and TensorFlow1.Introduction to Python and TensorFlow
1.Introduction to Python and TensorFlow
 
파이썬 생존 안내서 (자막)
파이썬 생존 안내서 (자막)파이썬 생존 안내서 (자막)
파이썬 생존 안내서 (자막)
 
EMOCON 2017 F/W - Deep Learning과 Keras 기초
EMOCON 2017 F/W - Deep Learning과 Keras 기초EMOCON 2017 F/W - Deep Learning과 Keras 기초
EMOCON 2017 F/W - Deep Learning과 Keras 기초
 
해커에게 전해들은 머신러닝 #1
해커에게 전해들은 머신러닝 #1해커에게 전해들은 머신러닝 #1
해커에게 전해들은 머신러닝 #1
 
2.supervised learning(epoch#2)-1
2.supervised learning(epoch#2)-12.supervised learning(epoch#2)-1
2.supervised learning(epoch#2)-1
 
Basic Understanding of the Deep
Basic Understanding of the DeepBasic Understanding of the Deep
Basic Understanding of the Deep
 
2.supervised learning(epoch#2)-2
2.supervised learning(epoch#2)-22.supervised learning(epoch#2)-2
2.supervised learning(epoch#2)-2
 
3.unsupervised learing
3.unsupervised learing3.unsupervised learing
3.unsupervised learing
 

Logistic Regression

  • 2. Logistic Regression 입력변수 x에 대하여 출력변수 Y가 1이 될 확률 추정 • 장점 : 계산비용이 적고, 구현하기 쉬우며, 결과해석을 위한 지식 표현이 쉽다 • 단점 : 언더피팅(underfitting) 경향이 있어 정확도가 낮게 나올수도 있다.
  • 3. Logistic Regression? 입력변수 x에 대하여 출력변수 Y가 1이 될 확률 추정 • 장점 : 계산비용이 적고, 구현하기 쉬우며, 결과해석을 위한 지식 표현이 쉽다 • 단점 : 언더피팅(underfitting) 경향이 있어 정확도가 낮게 나올수도 있다.
  • 4. • 데이터가 표시된 좌표평면을 가로지르는 최적선(best-fit line)을 구하는 것 • 회귀는 가장 알맞은 매개변수의 집합을 찾으려는 양상을 나타낸다 • 종속변수가 비선형일 경우 선형 모형을 적용하기 어렵다 • 비선형 -> Logistic Regression! Regression Analysis
  • 5. • 연령, 자동차 소유 유무, 연간소득 등과 같은 특성이 개인신용분량 여부에 어떠한 영향을 미치는가? • 유권자의 연령, 성별, 거주지역, 학력 등이 선호하는 후보선택에 어떠한 영향을 미치는가? • 흡연 유무, 주량, 직업, 비만 정도, 키와 같은 특성이 특정한 질병발생에 어떠한 영향을 미치는가? • 선택대상이 되는 상표들에 대한 평가와 응답자의 특성이 선호상표 선택에 어떠한 영향을 미치는가?
  • 7. Logistic Function An explanation of a Logistic Regression begins with an explanation of the “Logistic Function”
  • 8. Logistic Regression! == odds :일어날 확률 / 안 일어날 확률
  • 9. 회귀계수에 따라 특정 집단에 속할 확률이 달라짐 이 계수의 해석으로 어떤 변수가 확률을 높이거나 낮추는 요인인지 알수있게함 If there are multiple explanatory variables, the above expression can be revised to Multiple Logistic Regression!
  • 10. How it works? in “ML in Action”
  • 11. Optimization Algorithm • 가장 알맞은 매개변수를 찾기위해 최적화 알고리즘을 사용한다 • ML in Action에서는 GD, SGD를 이용
  • 12. Gradient Descent • 기울기가 낮은(높은)쪽으로 계속 이동시켜서 극값에 이를때까지 반복 • 모든 차원과 모든 공간에서의 적용에서도 사용가능(무한까지도) • 극값 이동에 대해 매우 많은 단계를 거쳐야하며, 함수의 곡률에 따라 거의 같은 위치에서 시작했음에도 불구하고 완전히 다른 결과로 이어질수도 있다 This Procedure is also known as gradient ascent
  • 13. Stochastic Gradient Descent • 너무 많은 연산을 필요로하는 기존의 알고리즘(GD)을 보완 • 한번에 단 하나의 사례를 사용하여 가중치 계산 • Online Learning Algorithm, Not batch processing
  • 14. 미분 가능 : 변수 x의 값의 변화량에 대한 함수 f(x)의 변화량 비가 한없이 일정한 값에 가까워지는것 Activation Function (Sigmoid function) • 비선형적인 값들을 선형적으로 변환해준다 • 어떤 값이 시그모이드 함수를 거치면 미분 가능한 형태로 변환된다
  • 15. 미분 가능 : 변수 x의 값의 변화량에 대한 함수 f(x)의 변화량 비가 한없이 일정한 값에 가까워지는것 Activation Function (Sigmoid function) • 비선형적인 값들을 선형적으로 변환해준다 • 어떤 값이 시그모이드 함수를 거치면 미분 가능한 형태로 변환된다 Hmm.. It’s similar to…
  • 16. Let’s try using python!
  • 19.
  • 21. Case 2. Stochastic Gradient Ascent
  • 23. 알고리즘 개선 1. 불규칙적인 alpha 값 2. 임의 사례 선택
  • 24. Real Case. Logistic Regression
  • 25. http://archive.ics.uci.edu/ml/datasets/Horse+Colic 데이터를 정제할 필요가 있다 :( 1. 알수없는 값 = 0으로 처리 weights = weights + alpha * error dataMatrix[randIndex] weights = weights (dataMatrix[i] = 0) 2. 분류 표시 누락 = 무시 대체하기 어렵다
  • 26.
  • 27.
  • 29. Goal : to identify the various factors that may influence admission into graduate school rank : prestige of an applicant’s undergraduate alma mater Data : http://www.ats.ucla.edu/stat/data/binary.csv
  • 30. Rename because there is also the name of a method pandas DataFrame
  • 31. “get_dummies” helps how categorical variables are represented to prevent multicollinearity or the dummy variable trap, “prestige_1” is our baseline and exclude it from our fit
  • 32. add manually the intercept as constant and do a logistic regression