分類のための決定木

Pythonで学ぶ木ベースのMachine Learning

Elie Kawerk

Data Scientist

コース概要

  • 第1章: Classification And Regression Tree (CART)

  • 第2章: バイアス–バリアンスのトレードオフ

  • 第3章: バギングとランダムフォレスト

  • 第4章: ブースティング

  • 第5章: モデルチューニング

Pythonで学ぶ木ベースのMachine Learning

分類木

  • 個々の特徴に対する if-else の連続。

  • 目的: クラスラベルを推定。

  • 特徴とラベルの非線形関係を捉えられる。

  • 特徴量スケーリング不要(例: Standardization など)

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 と線形モデル

LRvsDT

Pythonで学ぶ木ベースのMachine Learning

練習しましょう!

Pythonで学ぶ木ベースのMachine Learning

Preparing Video For Download...