Lean.predict: probability of a given class and probability of actual class


I saw this command some where in the documentation or forums and cant find it any more.
Its part of the lean.predict or learn.get_predictions.

For a multi-class classification, this command will give the probabilities of actual class in the predictions by default. or we have the option to choose to give predictions for a specific class of interest.

Thank you for your help

1 Like

You may be thinking of learn.predict() or learn.get_preds()

Here is a bit of code that will give you the top 3 predictions and their % probabilities.

#function to get the arg_first_max, arg_second_max etc.,
def argNmax(a, N):
return np.argpartition(a.ravel(), -N)[-N]

prd_cat, num_cat, prob, data_text_c,first_cat, second_cat, third_cat = [],[],[],[],[],[],[]
for data_text in df_val[β€˜text’]:
cat_i, num_cat_i,prob_i = learn.predict(data_text)
pro = prob_i.numpy()*100
arg1max,arg2max,arg3max = argNmax(pro,1),argNmax(pro,2),argNmax(pro,3)
first_cat_percent = data_clas.classes[arg1max] + " " + str(round(pro[arg1max],2)) + β€œ%”
second_cat_percent = data_clas.classes[arg2max] + " " + str(round(pro[arg2max],2)) + β€œ%”
third_cat_percent = data_clas.classes[arg3max] + " " + str(round(pro[arg3max],2)) + β€œ%”

Thank you! I found what I was looking for. Its actually
from TextClassificationInterpretation.from_learner(learn)

After watching the class 9 video, I think this is an incorrect method to get the second and third probabilities of a given class from softmax.
What is a good way to get the second and third best guesses by the model while doing multi-class classification?