如何在 Scikit-Learn 的决策树算法中修改分裂标准(gini/entropy)?

How to amend the splitting criteria (gini/entropy) in a decision tree algorithm in Scikit-Learn?

我在二进制 class化问题上使用决策树算法,目标是最小化 class化(的成本)的误报(最大化 positive predicted value)诊断工具非常高)。

有没有办法在基尼系数/熵分裂标准中引入 weight 来惩罚误报错误class?

Here 例如,修改后的基尼系数为:

因此我想知道是否有任何方法可以在 Scikit-learn 中实现它?

编辑

使用 class_weight 产生了以下结果:

from sklearn import datasets as dts
iris_data = dts.load_iris()

X, y = iris_data.features, iris_data.targets
# take only classes 1 and 2 due to less separability
X = X[y>0]
y = y[y>0]
y = y - 1 # make binary labels

# define the decision tree classifier with only two levels at most and no class balance
dt = tree.DecisionTreeClassifier(max_depth=2, class_weight=None)

# fit the model, no train/test for simplicity
dt.fit(X[:55,:2], y[:55])

绘制决策边界和树 蓝色为正 (1):

同时胜过少数class(或更珍贵):

dt_100 = tree.DecisionTreeClassifier(max_depth=2, class_weight={1:100})

决策树class支持class_weight参数。

两个class问题,这个正好可以解决你的问题。通常这用于不平衡问题。对于两个以上的 class,无法提供单独的标签(据我所知)