Skip to content

Commit 8672ba2

Browse files
committed
update
1 parent a019afc commit 8672ba2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

nlp_class/sentiment.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,27 +152,32 @@ def tokens_to_vector(tokens, label):
152152

153153

154154
# check misclassified examples
155+
preds = model.predict(X)
155156
P = model.predict_proba(X)[:,1] # p(y = 1 | x)
156157

157158
# since there are many, just print the "most" wrong samples
158159
minP_whenYis1 = 1
159160
maxP_whenYis0 = 0
160161
wrong_positive_review = None
161162
wrong_negative_review = None
163+
wrong_positive_prediction = None
164+
wrong_negative_prediction = None
162165
for i in range(N):
163166
p = P[i]
164167
y = Y[i]
165168
if y == 1 and p < 0.5:
166169
if p < minP_whenYis1:
167170
wrong_positive_review = orig_reviews[i]
171+
wrong_positive_prediction = preds[i]
168172
minP_whenYis1 = p
169173
elif y == 0 and p > 0.5:
170174
if p > maxP_whenYis0:
171175
wrong_negative_review = orig_reviews[i]
176+
wrong_negative_prediction = preds[i]
172177
maxP_whenYis0 = p
173178

174-
print("Most wrong positive review (prob = %s):" % minP_whenYis1)
179+
print("Most wrong positive review (prob = %s, pred = %s):" % (minP_whenYis1, wrong_positive_prediction))
175180
print(wrong_positive_review)
176-
print("Most wrong negative review (prob = %s):" % maxP_whenYis0)
181+
print("Most wrong negative review (prob = %s, pred = %s):" % (maxP_whenYis0, wrong_negative_prediction))
177182
print(wrong_negative_review)
178183

0 commit comments

Comments
 (0)