Ril*_*Hun 1 python machine-learning scikit-learn xgboost
我有一个高度不平衡的 3 个类别的数据集。为了解决这个问题,我sample_weight在 XGBClassifier 中应用了数组,但我没有注意到建模结果有任何变化?分类报告(混淆矩阵)中的所有指标都是相同的。执行上有问题吗?
班级比例:
military: 1171
government: 34852
other: 20869
Run Code Online (Sandbox Code Playgroud)
例子:
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
])
Run Code Online (Sandbox Code Playgroud)
数据集样本:
data = pd.DataFrame({'entity_name': ['UNICEF', 'US Military', 'Ryan Miller'],
'class': ['government', 'military', 'other']})
Run Code Online (Sandbox Code Playgroud)
分类报告
eval_metric. eval_metric=merror或mlogloss,然后将结果发布给我们。你向我们展示了['precision','recall','f1-score','support'],但这是次优的,或者完全被破坏了,除非你以多类感知、不平衡感知的方式计算它们。military: government: other1: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)。| 归档时间: |
|
| 查看次数: |
6640 次 |
| 最近记录: |