I am trying to create a function that returns the most common element from an array it is passed. My code looks like this:
def get_classification(classes):
from collections import Counter
count = Counter(classes)
return count.most_common()[0]
And it is properly returning the most common element. However, it returns it in the format element, count
such as:
3.0, 2
2.0, 3
1.0, 3
I don't want it to return that tuple. I just need it to return the most common element. How is that possible?
I have tried the solution:
counts = numpy.bincount(classes)
final = numpy.argmax(counts)
return final
But that did not work for me either. Any advice would be greatly appreciated.