SlideShare a Scribd company logo
Machine Learning
with Python
Algorithm chains and Pipelines
1
Contacts
Haesun Park
Email : haesunrpark@gmail.com
Meetup: https://www.meetup.com/Hongdae-Machine-Learning-Study/
Facebook : https://facebook.com/haesunrpark
Blog : https://tensorflow.blog
2
Book
파이썬 라이브러리를 활용한 머신러닝, 박해선.
(Introduction to Machine Learning with Python, Andreas
Muller & Sarah Guido의 번역서입니다.)
번역서의 1장과 2장은 블로그에서 무료로 읽을 수 있습니다.
원서에 대한 프리뷰를 온라인에서 볼 수 있습니다.
Github:
https://github.com/rickiepark/introduction_to_ml_with_python/
3
Algorithm Chains
4
cancer + MinMaxScaler + SVC
5
𝑥 − 𝑥#$%
𝑥#&' − 𝑥#$%
모든 특성이
0과 1사이에 위치
train과 test의 스케일 조정
6
매개변수 탐색: Simple GridSearchCV
새로운 데이터는 스케일 조정에 사용되지 않은 것입니다.
하지만 GridSearchCV안에서 검증할 땐 스케일 조정에 사용한 후입니다.
7
Validation vs. Predict
8
교차검증
테스트세트 예측
검증폴드의 정보 누설
Simple Pipeline
9
임의 문자열(이중 밑줄 문자만 제외)튜플
scaler à svm
scaler à svm
Pipeline + GridSearchCV
10
두 개의
밑줄 문자
Validation vs. Predict 2
11
교차검증
테스트세트 예측
검증폴드가 누설되지 않음
정보 누설의 예
헤이스티, 팁시라니, 프리드먼의 ESL에 포함된 예제
12
1만개의 랜덤 특성
5%=500개 특성 선택
Pipeline
13
Pipeline 인터페이스
여러개의 어떤 Estimator 클래스와도 연결 가능합니다.
마지막 단계를 빼고는 모두 transform() 메서드가 있어야 합니다.
14
T1.fit()
àT1.transform()àT2.fit()
àT2.transform()àClassifier.fit()
T1.transform()àT2.transform()
àClassifier.predict()
make_pipeline
파이프라인 단계에 자동으로 이름을 할당합니다.
15
소문자 클래스 이름
두 개 이상일 때
Pipeline 단계에 접근하기
선형 모델의 계수나 PCA 주성분을 확인할 때
named_steps 속성에 대해 단계 이름을 키로 하여 접근합니다.
16
그리드서치 안의 Pipeline 속성 접근하기
17
GridSearchCV의 best_estimator_
속성에 최적의 Pipeline 모델 저장
전처리 매개변수를 위한 그리드서치
18
최적의 다항식 차수를
검증 세트 점수로 찾음
선택된 다항 특성 확인
19
모델 선택을 위한 그리드서치
파이프라인의 구성 단계를 탐색 대상으로 삼을 수 있습니다.
매개변수 그리드 리스트를 사용합니다.
20
랜덤포레스트는 전처리가 필요 없습니다.
그리드서치로 모델 선택
21
요약 및 정리
Pipeline 클래스는 여러 처리 단계를 하나의 객체로 캡슐화 합니다.
전처리가 있는 매개변수 선택에서는 올바른 교차검증을 위해 필수적입니다.
매개변수와 모델 등 탐색 범위가 커지면 시간이 많이 걸릴 수 있습니다.
실험 단계에서는 처리 단계가 꼭 필요한지 검토하고 너무 복잡하게 만들지
않습니다.
22
감사합니다.
23

More Related Content

What's hot

데이터분석의 길 3 “r 워크플로우 (스토리텔링)”
데이터분석의 길 3   “r 워크플로우 (스토리텔링)”데이터분석의 길 3   “r 워크플로우 (스토리텔링)”
데이터분석의 길 3 “r 워크플로우 (스토리텔링)”
Jaimie Kwon (권재명)
 
효율적 데이터 과학을 위한 7가지 팁
효율적 데이터 과학을 위한 7가지 팁효율적 데이터 과학을 위한 7가지 팁
효율적 데이터 과학을 위한 7가지 팁
Jaimie Kwon (권재명)
 
Doing math with python.ch01
Doing math with python.ch01Doing math with python.ch01
Doing math with python.ch01
Seok-joon Yun
 
데이터분석의 길 4: “고수는 통계학습의 달인이다”
데이터분석의 길 4:  “고수는 통계학습의 달인이다”데이터분석의 길 4:  “고수는 통계학습의 달인이다”
데이터분석의 길 4: “고수는 통계학습의 달인이다”
Jaimie Kwon (권재명)
 
tsfresh_suman2
tsfresh_suman2tsfresh_suman2
tsfresh_suman2
suman_lim
 
Chapter 11 Practical Methodology
Chapter 11 Practical MethodologyChapter 11 Practical Methodology
Chapter 11 Practical Methodology
KyeongUkJang
 

What's hot (6)

데이터분석의 길 3 “r 워크플로우 (스토리텔링)”
데이터분석의 길 3   “r 워크플로우 (스토리텔링)”데이터분석의 길 3   “r 워크플로우 (스토리텔링)”
데이터분석의 길 3 “r 워크플로우 (스토리텔링)”
 
효율적 데이터 과학을 위한 7가지 팁
효율적 데이터 과학을 위한 7가지 팁효율적 데이터 과학을 위한 7가지 팁
효율적 데이터 과학을 위한 7가지 팁
 
Doing math with python.ch01
Doing math with python.ch01Doing math with python.ch01
Doing math with python.ch01
 
데이터분석의 길 4: “고수는 통계학습의 달인이다”
데이터분석의 길 4:  “고수는 통계학습의 달인이다”데이터분석의 길 4:  “고수는 통계학습의 달인이다”
데이터분석의 길 4: “고수는 통계학습의 달인이다”
 
tsfresh_suman2
tsfresh_suman2tsfresh_suman2
tsfresh_suman2
 
Chapter 11 Practical Methodology
Chapter 11 Practical MethodologyChapter 11 Practical Methodology
Chapter 11 Practical Methodology
 

More from Haesun Park

사이킷런 최신 변경 사항 스터디
사이킷런 최신 변경 사항 스터디사이킷런 최신 변경 사항 스터디
사이킷런 최신 변경 사항 스터디
Haesun Park
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 9장 텐서플로 시작하기
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 9장 텐서플로 시작하기[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 9장 텐서플로 시작하기
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 9장 텐서플로 시작하기
Haesun Park
 
(Handson ml)ch.8-dimensionality reduction
(Handson ml)ch.8-dimensionality reduction(Handson ml)ch.8-dimensionality reduction
(Handson ml)ch.8-dimensionality reduction
Haesun Park
 
(Handson ml)ch.7-ensemble learning and random forest
(Handson ml)ch.7-ensemble learning and random forest(Handson ml)ch.7-ensemble learning and random forest
(Handson ml)ch.7-ensemble learning and random forest
Haesun Park
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
Haesun Park
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 5장. 서포트 벡터 머신
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 5장. 서포트 벡터 머신[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 5장. 서포트 벡터 머신
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 5장. 서포트 벡터 머신
Haesun Park
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
Haesun Park
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 3장. 분류
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 3장. 분류[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 3장. 분류
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 3장. 분류
Haesun Park
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
Haesun Park
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 1장. 한눈에 보는 머신러닝
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 1장. 한눈에 보는 머신러닝[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 1장. 한눈에 보는 머신러닝
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 1장. 한눈에 보는 머신러닝
Haesun Park
 
6.algorithm chains and piplines(epoch#2)
6.algorithm chains and piplines(epoch#2)6.algorithm chains and piplines(epoch#2)
6.algorithm chains and piplines(epoch#2)
Haesun Park
 
5.model evaluation and improvement(epoch#2) 2
5.model evaluation and improvement(epoch#2) 25.model evaluation and improvement(epoch#2) 2
5.model evaluation and improvement(epoch#2) 2
Haesun Park
 
5.model evaluation and improvement(epoch#2) 1
5.model evaluation and improvement(epoch#2) 15.model evaluation and improvement(epoch#2) 1
5.model evaluation and improvement(epoch#2) 1
Haesun Park
 
4.representing data and engineering features(epoch#2)
4.representing data and engineering features(epoch#2)4.representing data and engineering features(epoch#2)
4.representing data and engineering features(epoch#2)
Haesun Park
 
3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)
Haesun Park
 
2.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-32.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-3
Haesun Park
 
2.supervised learning(epoch#2)-2
2.supervised learning(epoch#2)-22.supervised learning(epoch#2)-2
2.supervised learning(epoch#2)-2
Haesun Park
 
2.supervised learning(epoch#2)-1
2.supervised learning(epoch#2)-12.supervised learning(epoch#2)-1
2.supervised learning(epoch#2)-1
Haesun Park
 
5.model evaluation and improvement
5.model evaluation and improvement5.model evaluation and improvement
5.model evaluation and improvement
Haesun Park
 
4.representing data and engineering features
4.representing data and engineering features4.representing data and engineering features
4.representing data and engineering features
Haesun Park
 

More from Haesun Park (20)

사이킷런 최신 변경 사항 스터디
사이킷런 최신 변경 사항 스터디사이킷런 최신 변경 사항 스터디
사이킷런 최신 변경 사항 스터디
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 9장 텐서플로 시작하기
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 9장 텐서플로 시작하기[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 9장 텐서플로 시작하기
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 9장 텐서플로 시작하기
 
(Handson ml)ch.8-dimensionality reduction
(Handson ml)ch.8-dimensionality reduction(Handson ml)ch.8-dimensionality reduction
(Handson ml)ch.8-dimensionality reduction
 
(Handson ml)ch.7-ensemble learning and random forest
(Handson ml)ch.7-ensemble learning and random forest(Handson ml)ch.7-ensemble learning and random forest
(Handson ml)ch.7-ensemble learning and random forest
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 5장. 서포트 벡터 머신
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 5장. 서포트 벡터 머신[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 5장. 서포트 벡터 머신
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 5장. 서포트 벡터 머신
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 4장. 모델 훈련
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 3장. 분류
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 3장. 분류[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 3장. 분류
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 3장. 분류
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 2장. 머신러닝 프로젝트 처음부터 끝까지
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 1장. 한눈에 보는 머신러닝
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 1장. 한눈에 보는 머신러닝[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 1장. 한눈에 보는 머신러닝
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 1장. 한눈에 보는 머신러닝
 
6.algorithm chains and piplines(epoch#2)
6.algorithm chains and piplines(epoch#2)6.algorithm chains and piplines(epoch#2)
6.algorithm chains and piplines(epoch#2)
 
5.model evaluation and improvement(epoch#2) 2
5.model evaluation and improvement(epoch#2) 25.model evaluation and improvement(epoch#2) 2
5.model evaluation and improvement(epoch#2) 2
 
5.model evaluation and improvement(epoch#2) 1
5.model evaluation and improvement(epoch#2) 15.model evaluation and improvement(epoch#2) 1
5.model evaluation and improvement(epoch#2) 1
 
4.representing data and engineering features(epoch#2)
4.representing data and engineering features(epoch#2)4.representing data and engineering features(epoch#2)
4.representing data and engineering features(epoch#2)
 
3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)
 
2.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-32.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-3
 
2.supervised learning(epoch#2)-2
2.supervised learning(epoch#2)-22.supervised learning(epoch#2)-2
2.supervised learning(epoch#2)-2
 
2.supervised learning(epoch#2)-1
2.supervised learning(epoch#2)-12.supervised learning(epoch#2)-1
2.supervised learning(epoch#2)-1
 
5.model evaluation and improvement
5.model evaluation and improvement5.model evaluation and improvement
5.model evaluation and improvement
 
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