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

时间:2018-04-24 13:14:27

标签: python scikit-learn classification decision-tree gini

我使用决策树算法处理二元分类问题,目标是最小化分类的误报(最大化positive predicted value)(诊断工具的成本非常高)。

有没有办法在gini / entropy分割标准中引入weight来惩罚误报误分类?

例如,

Here,修改后的Gini索引为:

enter image description 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)

enter image description here

虽然超过少数群体(或更珍贵):

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

enter image description here

1 个答案:

答案 0 :(得分:1)

决策树分类器支持class_weight参数。

在两个课程问题中,这可以完全解决您的问题。通常,这用于不平衡的问题。对于两个以上的类,不可能提供单独的标签(据我所知)