Skip to content

Commit 3fc6f4e

Browse files
MorvanZhouMorvan Zhou
authored and
Morvan Zhou
committed
update
1 parent d6f7fbf commit 3fc6f4e

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

tutorial-contents/302_classification.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def forward(self, x):
6363
pred_y = prediction.data.numpy().squeeze()
6464
target_y = y.data.numpy()
6565
plt.scatter(x.data.numpy()[:, 0], x.data.numpy()[:, 1], c=pred_y, s=100, lw=0, cmap='RdYlGn')
66-
accuracy = sum(pred_y == target_y)/200
66+
accuracy = sum(pred_y == target_y)/200.
6767
plt.text(1.5, -4, 'Accuracy=%.2f' % accuracy, fontdict={'size': 20, 'color': 'red'})
6868
plt.pause(0.1)
6969

tutorial-contents/401_CNN.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def forward(self, x):
9898
if step % 50 == 0:
9999
test_output = cnn(test_x)
100100
pred_y = torch.max(test_output, 1)[1].data.squeeze()
101-
accuracy = sum(pred_y == test_y) / test_y.size(0)
101+
accuracy = sum(pred_y == test_y) / float(test_y.size(0))
102102
print('Epoch: ', epoch, '| train loss: %.4f' % loss.data[0], '| test accuracy: %.2f' % accuracy)
103103

104104

tutorial-contents/402_RNN_classifier.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def forward(self, x):
9797
if step % 50 == 0:
9898
test_output = rnn(test_x) # (samples, time_step, input_size)
9999
pred_y = torch.max(test_output, 1)[1].data.numpy().squeeze()
100-
accuracy = sum(pred_y == test_y) / test_y.size
100+
accuracy = sum(pred_y == test_y) / float(test_y.size)
101101
print('Epoch: ', epoch, '| train loss: %.4f' % loss.data[0], '| test accuracy: %.2f' % accuracy)
102102

103103
# print 10 predictions from test data

0 commit comments

Comments
 (0)