如何使用DecisionTreeClassifier平衡分类? [英] How to balance classification using DecisionTreeClassifier?
问题描述
我有一个数据集,其中的类是不平衡的.这些类是0
,1
或2
.
I have a data set where the classes are unbalanced. The classes are either 0
, 1
or 2
.
如何计算每个班级的预测误差,然后在scikit-learn中相应地重新平衡weights
?
How can I calculate the prediction error for each class and then re-balance weights
accordingly in scikit-learn?
推荐答案
如果您想完全平衡(将每个班级视为同等重要),您可以简单地通过class_weight='balanced'
,如
If you want to fully balance (treat each class as equally important) you can simply pass class_weight='balanced'
, as it is stated in the docs:
平衡"模式使用y的值自动调整 权重与输入数据中的类频率成反比 为
n_samples / (n_classes * np.bincount(y))
The "balanced" mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as
n_samples / (n_classes * np.bincount(y))
这篇关于如何使用DecisionTreeClassifier平衡分类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!