我有一个由3个类组成的高度不平衡的数据集。为了解决这个问题,我在XGBClassifier中应用了sample_weight数组,但是我没有注意到建模结果中的任何变化?分类报告(混淆矩阵)中的所有指标都是相同的。实施中是否存在问题
班级比例:
military: 1171
government: 34852
other: 20869
示例:
pipeline = Pipeline([
('bow', CountVectorizer(analyzer=process_text)), # convert strings to integer counts
('tfidf', TfidfTransformer()), # convert integer counts to weighted TF-IDF scores
('classifier', XGBClassifier(sample_weight=compute_sample_weight(class_weight='balanced', y=y_train))) # train on TF-IDF vectors w/ Naive Bayes classifier
])
数据集示例:
data = pd.DataFrame({'entity_name': ['UNICEF', 'US Military', 'Ryan Miller'],
'class': ['government', 'military', 'other']})
分类报告
eval_metric
eval_metric=merror
或mlogloss
,然后将结果发布给我们。您向我们展示了['precision','recall','f1-score','support']
,但这是次优的,或者完全不符合要求的,除非您以多类感知、不平衡感知的方式计算它们李>military: government: other
1:30:18,或者百分比为2:61:37%。xgb.DMatrix..., weights)
手动设置每个类的权重sklearn.utils.class_weight.compute_sample_weight('balanced', ...)
之类的样板文件来为您提供最佳权重李>1 : 1/30 : 1/18
开始,尝试更多的极值。往复运动,因此稀有类的重量更高李>min_child_weight
设置得更高,因此它需要一些(少数类的)示例。从min_child_weight >= 2
(*最稀有类的权重)开始,然后尝试更高。当心过度拟合非常罕见的少数类(这就是为什么人们使用StratifiedKFold交叉验证来提供一些保护,但您的代码没有使用CV)李>相关问题 更多 >
编程相关推荐