0

I have a ndarray that includes probabilities for being associated to specific class. This is multi-class problem in which every record can be associated to class 0 - 4.

I used one of the classifiers of sckit-learn:

classifier = RandomForestClassifier(n_estimators=100)
predictions_proba = classifier.predict_proba(dataframe)

Let's look on predictions_proba

array([[ 0.2       ,  0.36      ,  0.32      ,  0.05      ,  0.07      ],
   [ 0.04      ,  0.54      ,  0.29      ,  0.08      ,  0.05      ],
   [ 0.05      ,  0.02      ,  0.        ,  0.93      ,  0.        ],
   ..., 
   [ 0.47777778,  0.2       ,  0.13      ,  0.19      ,  0.00222222],
   [ 0.5951746 ,  0.        ,  0.        ,  0.        ,  0.4048254 ],
   [ 0.        ,  0.        ,  0.        ,  0.13837252,  0.86162748]])

I would like to find the easiest way for finding the greatest probability in each sub array. For the example above I would like to return:

[ 0.36, 0.54, 0.93,..., 0.86162748]

0.36 is the greatest probability in the first array, 0.54 is the greatest probility in the second array, and so on.

3
  • 4
    Did you google for finding max in NumPy array? Commented Nov 17, 2016 at 20:05
  • Yeah. I didn't understand that I have to put the ndarray as a parameter to np.array. Commented Nov 17, 2016 at 20:11
  • Thanks you really helped me. Commented Nov 17, 2016 at 20:11

1 Answer 1

1
arr = np.array([[1,5],[7,3]])
# array([[1, 5],
#        [7, 3]])
arr.max(axis=1)
# array([5, 7])
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.