My program counts the number of times 3 different values appear and stores them in a list like this one classes = [class1,class2,class3]
I want to return the index of the biggest value, but these values will often be duplicates. If that is the case, I want to return an index chosen at random between the biggest values.
For example, if I have classes = [5,2,5], I want to output either 0 or 2. If I have classes = [1,1,1], 0,1 and 2 are fine. Finally, if I have classes = [1,10,1], I want to output 1.
So far I have pieced together this from other questions, but it's not behaving the way I want and I dont understand why.
classes = [class1,class2,class3]
dupes = [n for n, x in enumerate(classes) if x in classes[:n]]
class_prediction = dupes[random.randint(0,len(dupes))] + 1
(The +1 at the end is to return the actual class label instead of the index.)
Aucun commentaire:
Enregistrer un commentaire