Sklearn predict_proba - Predicting Class Probabilities

Python

To predict the class probability when using sklearn classification models we use the predict_proba function.

In the example below we have trained a logistic regression model and then use the predict_proba function to predict the class probabilities for each example in the test dataset.

 1|  from sklearn.linear_model import LogisticRegression
 2|  
 3|  #Initialise & Fit Model
 4|  model = LogisticRegression()
 5|  model.fit(X_train, y_train)
 6|  
 7|  # predict class probabilities for each example in X_test
 8|  y_pred_proba = model.predict_proba(X_test)
 9|  
10|  
Did you find this snippet useful?

Sign up for free to to add this to your code library