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

#1

Hello,

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
Pradeep

0 Likes

#2

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

0 Likes

#3

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]

#predict
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)) + “%”
prd_cat.append(data_clas.classes[arg1max])
first_cat.append(first_cat_percent)
second_cat.append(second_cat_percent)
third_cat.append(third_cat_percent)

0 Likes

#4

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

0 Likes

#5

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?

0 Likes