Created
January 7, 2022 07:47
-
-
Save pandanote-info/8044249416d5f6049e4154c2fa62a406 to your computer and use it in GitHub Desktop.
TF-IDFの計算用のサンプルコード片
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
# TF | |
aa = bow.copy() | |
np.set_printoptions(threshold=np.inf,formatter={'float': '{:.8f}'.format}) | |
for i in range(0,dim[0]): | |
ar = bow.getrow(i) | |
rowsum = np.matrix.sum(ar.todense()) | |
arr = ar/rowsum | |
aa[i] = arr | |
# IDF(ln) | |
for j in range(0,dim[1]): | |
ac = aa.getcol(j) | |
idf = math.log(dim[0]/ac.getnnz()) | |
aa[0:dim[0],j] = ac*idf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment