Skip to content

Instantly share code, notes, and snippets.

@anandology
Created March 15, 2017 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandology/5a19f29c31a5605b2011f5c3aec7cec7 to your computer and use it in GitHub Desktop.
Save anandology/5a19f29c31a5605b2011f5c3aec7cec7 to your computer and use it in GitHub Desktop.
Script to find most common features found from multiple runs of an algorithm with different parameters.
"""Script to find most common features found from
multiple runs of an algorithm with different parameters.
"""
from collections import Counter
runs = [
["a", "b", "c", "d", "e"],
["a", "b", "c", "d", "f"],
["a", "b", "c", "e", "g"],
["a", "b", "d", "f", "h"]
]
# approach 1
c = Counter()
for features in runs:
c.update(features)
print(c.most_common(5))
# approach 2
all_features = [f for features in runs for f in features]
print(all_features)
c = Counter(all_features)
print(c.most_common(5))
# print just the top features without the counts
top_features = [f for f, count in c.most_common(5)]
print(top_features)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment