我有一个数据集,其中的类是不平衡的。这些类是 0
、1
或 2
。
如何计算每个类别的预测误差,然后在 scikit-learn 中相应地重新平衡权重
?
最佳答案
如果你想完全平衡(将每个类视为同等重要),你可以简单地传递 class_weight='balanced'
,如 docs 中所述:
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))
关于python - 如何使用 DecisionTreeClassifier 来平衡分类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37522191/