如何使用DecisionTreeClassifier平衡分类? [英] How to balance classification using DecisionTreeClassifier?

查看:409
本文介绍了如何使用DecisionTreeClassifier平衡分类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据集,其中的类是不平衡的.这些类是012.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆