【发布时间】:2018-05-04 02:31:33
【问题描述】:
我想在不平衡分类问题上使用sklearn.ensemble.GradientBoostingClassifier。我打算针对Area Under the Receiver Operating Characteristic Curve (ROC AUC) 进行优化。为此,我想重新调整我的班级,使小班对分类器更重要。
这通常可以通过设置 class_weight = “balanced” 来完成(例如在 RandomForestClassifier 中),但 GradientBoostingClassifier 中没有这样的参数。
文档说:
“平衡”模式使用 y 的值自动调整权重,与输入数据中的类频率成反比,如 n_samples / (n_classes * np.bincount(y))
如果 y_train 是我的目标数据框,其中元素在 {0,1},那么文档暗示这应该与 class_weight = “balanced” 相同
sample_weight = y_train.shape[0]/(2*np.bincount(y_train))
clf = ensemble.GradientBoostingClassifier(**params)
clf.fit(X_train, y_train,sample_weight = sample_weight[y_train.values])
这是正确的还是我遗漏了什么?
【问题讨论】:
标签: python machine-learning scikit-learn