0

I created a model with sklearn for classification. When I call the function y_pred2 = clf.predict (features2) it returns a list with all the ids of my prediction

y_pred2 = clf.predict(features2)

Print Array

array([**5**, 5, 5, 1, 6, 1, 6, 1, 1, 1])

Up here I can add it to my dataframe without any problem df ['prediction'] = y_pred2

But I also want to record my multi-class probability at the best value

y_pred2 = clf.predict_proba(features2)[0]

array([0.02670249, 0.23888486, 0.00940765, 0.15213608, 0.02719888,
   **0.42038983**, 0.07503347, 0.02960037, 0.02064636])

But I also want to record the probability of my multi-class by the best value, but the return from the predict_proba function returns an array of all my class, how can I do to record the value of my prediction score.

Example according to my prediction my best class and first position 5 where probability value was 0.42038983. C

How can I take the best value from my array and write to my dataframe?

1
  • how did your Y look like before training? Commented Feb 6, 2020 at 2:41

1 Answer 1

1

so if we deal with the result as a normal list, we can try something like

y_pred2 = clf.predict_proba(features2)[0]
someclass = y_pred2.index(max(y_pred2)) # returns the class index *Maximum predicted value
itsprob = max(y_pred2) # returns the Portability *Maximum predicted value

then you can either class,prob variable in a df or how ever you like. i cant reproduce your whole scenario as i dont know all of your code

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.