분류용 의사결정나무

Python으로 배우는 트리 기반 Machine Learning

Elie Kawerk

Data Scientist

강의 개요

  • 1장: 분류·회귀 트리(CART)

  • 2장: 편향-분산 트레이드오프

  • 3장: 배깅과 랜덤 포레스트

  • 4장: 부스팅

  • 5장: 모델 튜닝

Python으로 배우는 트리 기반 Machine Learning

분류나무

  • 개별 특성에 대한 if-else 질문의 연쇄.

  • 목표: 클래스 라벨 추론.

  • 특성과 라벨 간 비선형 관계를 포착.

  • 특성 스케일링 불필요(예: 표준화 등).

Python으로 배우는 트리 기반 Machine Learning

유방암 데이터셋 2D 시각화

BC2D

Python으로 배우는 트리 기반 Machine Learning

의사결정나무 다이어그램

CART-rep

Python으로 배우는 트리 기반 Machine Learning

scikit-learn의 분류나무

# Import DecisionTreeClassifier
from sklearn.tree import DecisionTreeClassifier
# Import train_test_split
from sklearn.model_selection import train_test_split
# Import accuracy_score
from sklearn.metrics import accuracy_score

# Split the dataset into 80% train, 20% test X_train, X_test, y_train, y_test= train_test_split(X, y, test_size=0.2, stratify=y, random_state=1)
# Instantiate dt dt = DecisionTreeClassifier(max_depth=2, random_state=1)
Python으로 배우는 트리 기반 Machine Learning

scikit-learn의 분류나무

# Fit dt to the training set
dt.fit(X_train,y_train) 

# Predict the test set labels
y_pred = dt.predict(X_test)

# Evaluate the test-set accuracy accuracy_score(y_test, y_pred)
0.90350877192982459
Python으로 배우는 트리 기반 Machine Learning

결정 영역

결정 영역: 특성 공간에서 동일한 클래스 라벨이 할당되는 영역.

결정 경계: 서로 다른 결정 영역을 구분하는 경계.

DR

Python으로 배우는 트리 기반 Machine Learning

결정 영역: CART vs. 선형 모델

LRvsDT

Python으로 배우는 트리 기반 Machine Learning

연습해 봅시다!

Python으로 배우는 트리 기반 Machine Learning

Preparing Video For Download...