2017-08-04 30 views

回答

1

在水中堆疊集成算法採用GLM作爲元學習算法,這樣你就可以解釋的係數的大小GLM metalearner作爲每個基礎學習者在合奏中進行預測的「重要性」。

在Stacked Ensemble文檔中的簡單example中,我們訓練了一個2模型(GBM,RF)集合。這是你如何檢查metalearner GLM的係數在Python:

import h2o 
from h2o.estimators.random_forest import H2ORandomForestEstimator 
from h2o.estimators.gbm import H2OGradientBoostingEstimator 
from h2o.estimators.stackedensemble import H2OStackedEnsembleEstimator 
h2o.init() 

# Import a sample binary outcome train/test set into H2O 
train = h2o.import_file("https://s3.amazonaws.com/erin-data/higgs/higgs_train_10k.csv") 
test = h2o.import_file("https://s3.amazonaws.com/erin-data/higgs/higgs_test_5k.csv") 

# Identify predictors and response 
x = train.columns 
y = "response" 
x.remove(y) 

# For binary classification, response should be a factor 
train[y] = train[y].asfactor() 
test[y] = test[y].asfactor() 

# Number of CV folds (to generate level-one data for stacking) 
nfolds = 5 

# Generate a 2-model ensemble (GBM + RF) 

# Train and cross-validate a GBM 
my_gbm = H2OGradientBoostingEstimator(distribution="bernoulli", 
             ntrees=10, 
             max_depth=3, 
             min_rows=2, 
             learn_rate=0.2, 
             nfolds=nfolds, 
             fold_assignment="Modulo", 
             keep_cross_validation_predictions=True, 
             seed=1) 
my_gbm.train(x=x, y=y, training_frame=train) 

# Train and cross-validate a RF 
my_rf = H2ORandomForestEstimator(ntrees=50, 
           nfolds=nfolds, 
           fold_assignment="Modulo", 
           keep_cross_validation_predictions=True, 
           seed=1) 
my_rf.train(x=x, y=y, training_frame=train) 


# Train a stacked ensemble using the GBM and RF above 
ensemble = H2OStackedEnsembleEstimator(base_models=[my_gbm.model_id, my_rf.model_id]) 
ensemble.train(x=x, y=y, training_frame=train) 

# Grab the metalearner GLM fit & print normalized coefficients 
metafit = h2o.get_model(ensemble.metalearner()['name']) 
metafit.coef_norm() 

此打印如下:

{u'DRF_model_python_1502159734743_250': 0.6967886117663271, 
u'GBM_model_python_1502159734743_1': 0.48518914691349374, 
u'Intercept': 0.1466358030144971} 

因此,在這種情況下,隨機森林的預測是促進了集合預報超過GBM。

如果您在一個測試集上評估基礎模型,您可以看到隨機森林比GBM稍好一點,因此合理選擇RF預測稍好於GBM是合理的(儘管並不總是測試集性能和metalearner變量重要性之間的直接1-1對應關係)。

my_gbm.model_performance(test).auc() # 0.7522498803447679 
my_rf.model_performance(test).auc() # 0.7698039263004212 

有計劃expose the metalearner as an argument使用戶可以使用任何H2O的監督ML交易算法,作爲在未來metalearner,在這種情況下,你可以看看算法的變量重要性得到相同信息,因爲所有H2O算法都計算可變重要性。