0

我正在尝试使用带有决策树桩的 AdaBoostClassifier 作为基本分类器。我注意到 AdaBoostClassifier 所做的权重调整一直给我 SAMME.R 和 SAMME 选项的错误。

这是我正在做的事情的简要概述

def train_adaboost(features, labels):
    uniqLabels = np.unique(labels)
    allLearners = []
    for targetLab in uniqLabels:
        runs=[]
        for rrr in xrange(10):
            feats,labs = get_binary_sets(features, labels, targetLab)
            baseClf = DecisionTreeClassifier(max_depth=1, min_samples_leaf=1)
            baseClf.fit(feats, labs)

            ada_real = AdaBoostClassifier( base_estimator=baseClf, 
                                           learning_rate=1, 
                                           n_estimators=20, 
                                           algorithm="SAMME")
            runs.append(ada_real.fit(feats, labs))
        allLearners.append(runs)

    return allLearners

我查看了每个决策树分类器的拟合度,它们能够预测一些标签。然而,当我使用这个基分类器查看 AdaBoostClassifier 时,我得到了关于权重提升算法的错误。

def compute_confidence(allLearners, dada, labbo):
    for ii,thisLab in enumerate(allLearners):
        for jj, thisLearner in enumerate(thisLab):
            #accessing thisLearner's methods here 

这些方法会给出如下错误:

ipdb> thisLearner.predict_proba(myData)

PATHTOPACKAGE/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.py:727: RuntimeWarning: invalid value encountered in double_scalars proba /= self.estimator_weights_.sum() *** ValueError: 'axis' entry is out of bounds

ipdb> thisLearner.predict(myData)

PATHTOPACKAGE/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.py:639: RuntimeWarning: invalid value encountered in double_scalars pred /= self.estimator_weights_.sum() *** IndexError: 0-d arrays can only use a single () or a list of newaxes (and a single ...) as an index

我为 adaboost 尝试了 SAMME.R 算法,但由于这个错误,在这种情况下我什至无法适应 adaboost [...]

File "PATH/sklearn/ensemble/weight_boosting.py", line 388, in fit return super(AdaBoostClassifier, self).fit(X, y, sample_weight)

File "PATH/sklearn/ensemble/weight_boosting.py", line 124, in fit X_argsorted=X_argsorted)

File "PATH/sklearn/ensemble/weight_boosting.py", line 435, in _boost X_argsorted=X_argsorted)

File "PATH/sklearn/ensemble/weight_boosting.py", line 498, in _boost_real (estimator_weight < 0)))

ValueError: non-broadcastable output operand with shape (1000) doesn't match the broadcast shape (1000,1000)

数据的维度实际上与分类器所期望的格式兼容,无论是在使用 adaboost 之前还是在我尝试测试经过训练的分类器时。这些错误表明什么?

4

1 回答 1

2

嗯,这有点违反直觉,来自 Matlab 中的编码。

显然实验室的尺寸是问题所在,即 (1000,1)。它必须是 (1000,)

添加这一行解决了它:

实验室 = 实验室[:,0]

于 2013-07-22T15:23:20.317 回答