Python Scikit-learn Perceptronic Inference Capabilities

I am using scikit-learn Perceptron's algorithm to perform binary classification. When using some of the other algorithms in the library (RandomForestClassifer, LogisticRegression, etc.) I can use the model.predict_proba()

algorithm to give the probability of getting a positive (1) for each example. Is there a way to get a similar output for the Perceptron algorithm?

The closest I was able to come with is model.decision_function()

one that outputs the trust score for the example based on the signed distance to the hyperplane, but I'm not sure how to convert these trust scores to the likelihood values ​​I want.

model.predict()

also only returns binary values.

+3


source to share


1 answer


I think what you want is CalibratedClassifierCV

:

from sklearn import linear_model
from sklearn.datasets import make_classification
from sklearn.calibration import CalibratedClassifierCV
# Build a classification task using 3 informative features
X, y = make_classification(n_samples=1000,
                           n_features=10,
                           n_informative=3,
                           n_redundant=0,
                           n_repeated=0,
                           n_classes=2,
                           random_state=0,
                           shuffle=False)


per = linear_model.Perceptron()

clf_isotonic = CalibratedClassifierCV(per, cv=10, method='isotonic')

clf_isotonic.fit(X[:900], y[:900])

preds = clf_isotonic.predict_proba(X[900:])
print preds

      



[Edit] You can also use this to have others linear_models

generate probabilities for classification problems

+1


source







All Articles