3

Can anyone help tell me how to convert the probability data from the results on predict_proba SVM. The results look like in the exemple below, but I want a list or an array containing only the second column and free of brackets.

[[ 0.15941701  0.84058299]
 [ 0.12190033  0.87809967]
 [ 0.06293788  0.93706212]
 ...
 [ 0.93175738  0.06824262]]
<class 'numpy.ndarray'>

Thank you.

Mauro Nogueira
  • 131
  • 2
  • 13
  • 1
    See this answer: [slicing numpy columns](https://stackoverflow.com/questions/4455076/how-to-access-the-ith-column-of-a-numpy-multidimensional-array). Extracting second column = a[:, 1]. – lmartens Sep 19 '17 at 11:47

1 Answers1

4

You just need to use the numpy indexing for multi-dimensional arrays. In this case you want all of the first dimension (rows) and only the second element in the second dimension (second column). So you use [:, 1]

a = np.array([
    [0.15941701, 0.84058299],
    [0.12190033, 0.87809967],
    [0.06293788, 0.93706212]])

a[:,1]

Which gives

[ 0.84058299  0.87809967  0.93706212]
Ken Syme
  • 3,532
  • 2
  • 17
  • 19