Created
February 28, 2019 13:40
-
-
Save eLtronicsVilla/30a3e3c4272bad75532dceea09c48573 to your computer and use it in GitHub Desktop.
Calculation of mode on given data set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sample code to calculate the mode of given data set | |
from collections import Counter | |
d_set = [1,3,3,4,5,7,8,9] | |
def mode(data): | |
# return a list might be more than one mode | |
c = Counter(data) # count occurance of the each item | |
max_count = max (c.values()) # find out max value in data | |
return [x_i for x_i , count in c.iteritems() if count == max_count ] | |
mode(d_set) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment