Python中的决策树桩

2024-05-23 13:31:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将Matlab代码转换成Python,得到完全相同的结果。在Matlab代码中,我有一个决策树桩,如下所示:

switch Model
    case 'DecisionStump'

        Weights = Pt; % Train the weak learner by weights Pt

        tree = fitctree(X,Y,'minparent',size(X,1)-sum(Weights==0),'prune','off','mergeleaves','off','Weights', Weights, 'CategoricalPredictors', CategoricalPredictors);

        h = compact(tree);

我使用下面的python代码构建了完全相同的决策树桩:

^{pr2}$

不过,这两个程序得到的结果略有不同,如果有人能帮助我,如果我遗漏了什么,那就太好了。(也许分类预测器应该包含在我的python代码中,但是我不知道怎么做!)在


Tags: the代码pttreemodeltrain树桩case