predict_proba for a cross-validated model predict_proba for a cross-validated model python python

predict_proba for a cross-validated model


This is now implemented as part of scikit-learn version 0.18. You can pass a 'method' string parameter to the cross_val_predict method. Documentation is here.

Example:

proba = cross_val_predict(logreg, X, y, cv=cv, method='predict_proba')

Also note that this is part of the new sklearn.model_selection package so you will need this import:

from sklearn.model_selection import cross_val_predict


An easy workaround for this is to create a wrapper class, which for your case would be

class proba_logreg(LogisticRegression):    def predict(self, X):        return LogisticRegression.predict_proba(self, X)

and then pass an instance of it as the classifier object to cross_val_predict

# cross validation probabilitiesprobas = cross_val_predict(proba_logreg(), X, y, cv=cv)


There is a function cross_val_predict that gives you the predicted values, but there is no such function for "predict_proba" yet. Maybe we could make that an option.