質問編集履歴
2
コード最新版に更新、試したことを追記[19:18]
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,19 +26,25 @@
|
|
26
26
|
|
27
27
|
id = 0
|
28
28
|
|
29
|
-
word_count
|
29
|
+
global word_count
|
30
30
|
|
31
31
|
for word in V:
|
32
32
|
|
33
|
-
print("
|
33
|
+
# print(word,end=" ")
|
34
|
+
|
35
|
+
# print(id)
|
34
36
|
|
35
37
|
# 行番号 i
|
36
38
|
|
37
39
|
for i,line in enumerate(f):
|
38
40
|
|
41
|
+
|
42
|
+
|
39
43
|
class_label = -2
|
40
44
|
|
41
45
|
line_w = line.split(" ")
|
46
|
+
|
47
|
+
#print(word)
|
42
48
|
|
43
49
|
if len(line_w) != 2:
|
44
50
|
|
@@ -54,29 +60,55 @@
|
|
54
60
|
|
55
61
|
# 単語番号 j
|
56
62
|
|
57
|
-
for j,w in enumerate(line_w):
|
63
|
+
for j,w in enumerate(line_w[1:]):
|
58
64
|
|
65
|
+
# print(w) OK
|
66
|
+
|
59
|
-
i
|
67
|
+
#print(word,w.split(":")[0])
|
68
|
+
|
69
|
+
#print(w.split(":")[0])
|
70
|
+
|
71
|
+
if w.split(":")[0] == word:
|
72
|
+
|
73
|
+
#print("◯")
|
74
|
+
|
75
|
+
#print(word)
|
76
|
+
|
77
|
+
# print(w) OK
|
60
78
|
|
61
79
|
word_count[class_label] += int(w.split(":")[1])
|
62
80
|
|
63
|
-
#
|
81
|
+
#score += int(w.split(":")[1])
|
64
82
|
|
83
|
+
# print(w,i)
|
65
84
|
|
85
|
+
# word_count[class_label] += 1 OK
|
86
|
+
|
87
|
+
# #print(word_count) OK
|
88
|
+
|
89
|
+
# #print(w.split(":")[1]) OK
|
90
|
+
|
91
|
+
# print(word_count[0] , "before") OK
|
66
92
|
|
67
93
|
score0 = score1 = 0
|
68
94
|
|
69
|
-
#print(word_count)
|
95
|
+
#print(word_count,id)
|
70
96
|
|
71
97
|
score0 = math.log2((word_count[0] + σ) / (neg_all_word + len(V)*σ))
|
72
98
|
|
73
99
|
score1 = math.log2((word_count[1] + σ) / (pos_all_word + len(V)*σ))
|
74
100
|
|
101
|
+
#print(word_count)
|
102
|
+
|
75
|
-
|
103
|
+
#word_count = [0,0]
|
104
|
+
|
105
|
+
|
76
106
|
|
77
107
|
condprob.append((id,score0,score1))
|
78
108
|
|
79
109
|
id += 1
|
110
|
+
|
111
|
+
|
80
112
|
|
81
113
|
```
|
82
114
|
|
@@ -93,3 +125,11 @@
|
|
93
125
|
https://pastebin.com/EEtSr5Le
|
94
126
|
|
95
127
|
Python 3.6.3
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
### 試したこと
|
132
|
+
|
133
|
+
コメントになっているようにトレースしていきました。
|
134
|
+
|
135
|
+
V にはtrain_data_pathに出現している単語の辞書(set()しているため重複なし)です。
|
1
コード情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -88,6 +88,8 @@
|
|
88
88
|
|
89
89
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
90
90
|
|
91
|
+
コードの一番上で開いているファイルを添付しています↓
|
91
92
|
|
93
|
+
https://pastebin.com/EEtSr5Le
|
92
94
|
|
93
95
|
Python 3.6.3
|