在scikit-learn中使用Adaboost的决策函数的定义(公式)是什么



我发现sklearn.ensemble.AdaBoostClassifier有一个方法decision_function

我认为这个函数应该返回一个与样本属于某个类别的可能性相关的值。我说得对吗?

但我在AdaBoostClassifier中找不到决策函数的公式,有人知道吗?

它正好位于它应该位于的位置-在AdaBoostClassifier的源中,目前在639 行

https://github.com/scikit-learn/scikit-learn/blob/51a765a/sklearn/ensemble/weight_boosting.py#L639

def decision_function(self, X):
    """Compute the decision function of ``X``.
    Parameters
    ----------
    X : {array-like, sparse matrix} of shape = [n_samples, n_features]
        The training input samples. Sparse matrix can be CSC, CSR, COO,
        DOK, or LIL. DOK and LIL are converted to CSR.
    Returns
    -------
    score : array, shape = [n_samples, k]
        The decision function of the input samples. The order of
        outputs is the same of that of the `classes_` attribute.
        Binary classification is a special cases with ``k == 1``,
        otherwise ``k==n_classes``. For binary classification,
        values closer to -1 or 1 mean more like the first or second
        class in ``classes_``, respectively.
    """
    check_is_fitted(self, "n_classes_")
    X = self._validate_X_predict(X)
    n_classes = self.n_classes_
    classes = self.classes_[:, np.newaxis]
    pred = None
    if self.algorithm == 'SAMME.R':
        # The weights are all 1. for SAMME.R
        pred = sum(_samme_proba(estimator, n_classes, X)
                   for estimator in self.estimators_)
    else:   # self.algorithm == "SAMME"
        pred = sum((estimator.predict(X) == classes).T * w
                   for estimator, w in zip(self.estimators_,
                                           self.estimator_weights_))
    pred /= self.estimator_weights_.sum()
    if n_classes == 2:
        pred[:, 0] *= -1
        return pred.sum(axis=1)
    return pred

相关内容

  • 没有找到相关文章

最新更新