例如:
params = {'n_estimators': 200, "max_depth": 4, 'subsample': 1, 'learning_rate': 0.1}boost = ensemble.GradientBoostingRegressor(**params)ghostBoost = ensemble.GradientBoostingRegressor(**params)...boost.fit(x, y)ghostBoost.fit(x, y)...predictionA = boost.predict(features)predictionB = ghostBoost.predict(features)
boost
和 ghostBoost
完全相同,但 predictionA
与 predictionB
不相等,这是为什么呢?
回答:
尝试为两个模型的random_state
构造参数设置相同的值。决策树的构建过程是随机的,因为每个节点会从可用特征中随机抽取max_features
个特征(无放回抽样)。
编辑:特征抽样是无放回进行的。当max_features=None
(默认值)时,所有特征都会被评估,但特征的顺序会发生变化,这在max_depth
不为None
且目标变量有非唯一值导致最佳特征分割出现平局时会产生影响。