jax
jax

Reputation: 4197

How to get predicted class label from predicted probabilities in one step?

Currently, I am using the given code bellow to calculated the probabilities score and predicted class labels.

y_score = cross_val_predict(clf, X, y, cv=10 ,method='predict_proba')
y_pred = cross_val_predict(clf, X, y, cv=10 ) 

But it a computationally costly method, because have to run entire model twice, is there any method that I can get both in one step. Or how can I translate probabilities into class labels?

thanks

Upvotes: 0

Views: 1589

Answers (1)

Nicolas Gervais
Nicolas Gervais

Reputation: 36704

With the probabilities, use np.argmax() if it's a one-hot encoded target array. It will return where the highest probability is (the prediction), e.g., row 1, 2, or 3.

Use np.round() if you have two classes in a 1D array, so you get predicted values of categories 0 and 1. You may have to convert to int for it to work.

Upvotes: 1

Related Questions