Skip to content
Advertisement

How to get Top 3 or Top N predictions using sklearn’s SGDClassifier

JavaScript

In the above code, clf.predict() prints only 1 best prediction for a sample from list X. I am interested in top 3 predictions for a particular sample in the list X, i know the function predict_proba/predict_log_proba returns a list of all probabilities for each feature in list Y, but it has to sorted and then associated with the features in list Y before getting the top 3 results. Is there any direct and efficient way?

Advertisement

Answer

There is no built-in function, but what is wrong with

JavaScript

?

As suggested by one of the comment, should change [-n:] to [:,-n:]

JavaScript
Advertisement