Skip to content

Instantly share code, notes, and snippets.

@otknoy
Last active January 1, 2016 17:29
Show Gist options
  • Save otknoy/8177987 to your computer and use it in GitHub Desktop.
Save otknoy/8177987 to your computer and use it in GitHub Desktop.
term-score 合ってるのかわからない。
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