Scikit-Learn:如何检索 KFold CV 的预测概率?

Scikit-Learn: How to retrieve prediction probabilities for a KFold CV?

我有一个包含图像和相关描述的数据集。我将它们分成两个独立的数据集,它们有自己的分类器(视觉和文本),现在我想结合这两个分类器的预测来形成最终预测。

但是,我的 类 是二进制的,不是 1 就是 0。我最终得到两个 n_samples 列表,其中填充了 1 和 0。我假设对于大多数 algorithms/classifiers 来说,这些信息不足以做出有用的预测(即当一个分类器预测 1 而另一个预测 0 时)。

因此我认为我可以使用预测的概率作为某种形式的决定性权重。 SKlearn 中的 SVC 具有 svm.SVC.predict_proba 功能。返回一个可能如下所示的数组:

[[ 0.9486674   0.0513326 ]
 [ 0.97346471  0.02653529]
 [ 0.9486674   0.0513326 ]]

但我似乎无法将其与我的 Kfold 交叉验证函数结合使用 cross_validation.cross_val_predict,因为它本身就是一个预测函数,不包含类似的概率预测输出。有没有办法将两者结合起来?还是我遗漏了什么?

可能:我是不是完全错误地解决了我的问题,有没有更好的方法来组合两个二元分类器的预测?

提前致谢

您需要执行 GridSearchCrossValidation 而不仅仅是 CV。 CV是用来做绩效评估的,本身并不适合评估器。

from sklearn.datasets import make_classification
from sklearn.svm import SVC
from sklearn.grid_search import GridSearchCV

# unbalanced classification
X, y = make_classification(n_samples=1000, weights=[0.1, 0.9])

# use grid search for tuning hyperparameters
svc = SVC(class_weight='auto', probability=True)
params_space = {'kernel': ['linear', 'poly', 'rbf']}
# set cv to your K-fold cross-validation
gs = GridSearchCV(svc, params_space, n_jobs=-1, cv=5)
# fit the estimator
gs.fit(X, y)
gs.predict_proba(X)

Out[136]: 
array([[ 0.0074817 ,  0.9925183 ],
       [ 0.03655982,  0.96344018],
       [ 0.0074933 ,  0.9925067 ],
       ..., 
       [ 0.02487791,  0.97512209],
       [ 0.01426704,  0.98573296],
       [ 0.98574072,  0.01425928]])