Last active
January 1, 2016 17:29
-
-
Save otknoy/8177987 to your computer and use it in GitHub Desktop.
term-score
合ってるのかわからない。
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
def term_score(topics): | |
labels_matrix = [[v for w, v in t] for t in topics] | |
beta_hat = numpy.array([numpy.array([w for w, v in t]) for t in topics]) | |
gmean = scipy.stats.gmean(beta_hat) | |
gmean_m = numpy.tile(gmean, (len(beta_hat), 1)) | |
ts = beta_hat * numpy.log(beta_hat / gmean_m) | |
new_topics = [] | |
for i in range(len(labels_matrix)): | |
new_topics.append([]) | |
for l, w in sorted(zip(labels_matrix[i], ts[i]), key=lambda x:-x[1]): | |
new_topics[i].append((w, l)) | |
return new_topics |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment