0

I'm doing multiclass classification in Python using basic Logistic Regression approach. I'm fitting my model and predicting the target variable and get something like this:

y_train=[4, 3, 8, ..., 5, 1, 2]

y_resul=[4, 3, 7, ..., 3, 1, 2]

So the model predicts each time the class result with the highest "significance". How can I predict the array of the most relevant class results within the array of predictions like that:

y_train=[4, 3, 8, ..., 5, 1, 2]

y_resul=[[4,2,1], [3,8,4], [7,9,8] ..., [3,4,9], [1,5,4] [2,1,3]]
Keithx
  • 2,994
  • 15
  • 42
  • 71
  • if you want the individual class probabilities for each class, you can use the `[predict_proba](http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html#sklearn.linear_model.LogisticRegression.predict_proba)' method. – Quickbeam2k1 Aug 30 '17 at 12:14
  • no, i need the prediction of top classes for each distinct class – Keithx Aug 30 '17 at 12:17
  • 1
    Of course you need to rank the class probalilities on your own. You want the three most relevant classes? Then you have to take a look at `predict_proba`. If not, I'm not understanding your question. – Quickbeam2k1 Aug 30 '17 at 12:20
  • As @Quickbeam2k1 said, its very easy to get top n classes from `predict_proba`. Once you have that see this question: https://stackoverflow.com/questions/6910641/how-to-get-indices-of-n-maximum-values-in-a-numpy-array – Vivek Kumar Aug 30 '17 at 12:30

1 Answers1

0

The description of method itself could be found under link: http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html#sklearn.linear_model.LogisticRegression.predict_proba

Keithx
  • 2,994
  • 15
  • 42
  • 71