【发布时间】:2018-10-04 18:32:23
【问题描述】:
我在二元分类问题上使用决策树算法,目标是最小化分类的误报(最大化positive predicted value)(诊断工具的成本非常高)。
有没有办法在基尼/熵分裂标准中引入weight 来惩罚误报错误分类?
以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):
虽然超过了少数类(或更珍贵):
dt_100 = tree.DecisionTreeClassifier(max_depth=2, class_weight={1:100})
【问题讨论】:
标签: python scikit-learn classification decision-tree gini