確率的勾配ブースティング(SGB)

Pythonで学ぶ木ベースのMachine Learning

Elie Kawerk

Data Scientist

勾配ブースティングの欠点

  • GBは網羅的な探索を行います。

  • 各CARTは最適な分割点と特徴量を探索して学習します。

  • その結果、同じ分割点や同じ特徴量を使うCARTが生じることがあります。

Pythonで学ぶ木ベースのMachine Learning

確率的勾配ブースティング

  • 各木は学習データの行をランダム抽出した部分集合で学習します。

  • サンプルは(学習データの40%〜80%)非復元抽出で取得します。

  • 分割点の選択時、特徴量も非復元でサンプリングします。

  • 結果:アンサンブルの多様性がさらに向上。

  • 効果:木のアンサンブルにさらなる分散を付与。

Pythonで学ぶ木ベースのMachine Learning

確率的勾配ブースティング:学習

SGB

Pythonで学ぶ木ベースのMachine Learning

sklearnでの確率的勾配ブースティング(autoデータ)

# Import models and utility functions
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error as MSE

# Set seed for reproducibility
SEED = 1

# Split dataset into 70% train and 30% test
X_train, X_test, y_train, y_test = train_test_split(X,y, 
                                                    test_size=0.3, 
                                                    random_state=SEED)
Pythonで学ぶ木ベースのMachine Learning

sklearnでの確率的勾配ブースティング(autoデータ)

# Instantiate a stochastic GradientBoostingRegressor 'sgbt'
sgbt = GradientBoostingRegressor(max_depth=1, 
                                 subsample=0.8,
                                 max_features=0.2,
                                 n_estimators=300,             
                                 random_state=SEED)

# Fit 'sgbt' to the training set sgbt.fit(X_train, y_train) # Predict the test set labels y_pred = sgbt.predict(X_test)
Pythonで学ぶ木ベースのMachine Learning

sklearnでの確率的勾配ブースティング(autoデータ)

# Evaluate test set RMSE 'rmse_test'
rmse_test = MSE(y_test, y_pred)**(1/2)

# Print 'rmse_test'
print('Test set RMSE: {:.2f}'.format(rmse_test))
Test set RMSE: 3.95
Pythonで学ぶ木ベースのMachine Learning

練習しましょう!

Pythonで学ぶ木ベースのMachine Learning

Preparing Video For Download...