質問編集履歴
1
コードと実行結果
test
CHANGED
File without changes
|
test
CHANGED
@@ -53,3 +53,63 @@
|
|
53
53
|
助言いただければ幸いです。
|
54
54
|
|
55
55
|
よろしくお願いいたします。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
追記
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
現在のコード
|
66
|
+
|
67
|
+
#!/usr/bin/python
|
68
|
+
|
69
|
+
# -*- coding: utf-8 -*-
|
70
|
+
|
71
|
+
import codecs
|
72
|
+
|
73
|
+
import gensim
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
# Lowcorpusメソッドで、テキストファイルを読み込み
|
78
|
+
|
79
|
+
corpus = gensim.corpora.lowcorpus.LowCorpus('sample_wakachi_100_w.txt')
|
80
|
+
|
81
|
+
f0 = codecs.open('per_40_sample_corpus.txt', 'w', 'utf-8')
|
82
|
+
|
83
|
+
f0.write(str(corpus))
|
84
|
+
|
85
|
+
f0.close()
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
# gensim の LdaModelメソッドに生成した corpus を渡して、LDAモデルを生成
|
90
|
+
|
91
|
+
lda = gensim.models.ldamodel.LdaModel(corpus = corpus, num_topics = 40, id2word\
|
92
|
+
|
93
|
+
=corpus.id2word, minimum_probability = 0.0)
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
per = lda.log_perplexity(corpus, total_docs = None)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
f1 = codecs.open('per_40_per.txt', 'w', 'utf-8')
|
102
|
+
|
103
|
+
f1.write(str(per))
|
104
|
+
|
105
|
+
f1.close()
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
-6.71820347253
|
114
|
+
|
115
|
+
```
|