2

I want to retrieve only the non zero class probabilities. My code below keeps generating the following error

enter image description here

print(clf.predict(xtest))
pp = clf.predict_proba(xtest)[0] 
pp[:] = ([ind,value] for ind,value in enumerate(pp) if value > 0)

for ind,val in enumerate(pp):
    print('\t',clf.classes_[pp[ind][0]],'->',pp[ind][1])
print('\n\n\n\n')
Venkatachalam
  • 16,288
  • 9
  • 49
  • 77

1 Answers1

0

Try this!

pp = clf.predict_proba(xtest)[0] 
pp = [[ind,value] for ind,value in enumerate(pp) if value > 0]

you were over writing elements of float array with a generator.

If you remove [:], you can store it as a generator, but it will not allow indexing. Hence try using list (square braces).

Venkatachalam
  • 16,288
  • 9
  • 49
  • 77
  • 1
    Thanks for that! I tried the folowing: templist = [] and templist[:] = ([ind,value] for....) This seems to work too. But yours is a neat way to avoid making a new list – EmperorPenguin Jan 06 '19 at 05:55