diff --git a/tutorial-contents/302_classification.py b/tutorial-contents/302_classification.py index 98b8653..54120bc 100644 --- a/tutorial-contents/302_classification.py +++ b/tutorial-contents/302_classification.py @@ -63,7 +63,7 @@ for t in range(100): pred_y = prediction.data.numpy().squeeze() target_y = y.data.numpy() plt.scatter(x.data.numpy()[:, 0], x.data.numpy()[:, 1], c=pred_y, s=100, lw=0, cmap='RdYlGn') - accuracy = sum(pred_y == target_y)/200 + accuracy = sum(pred_y == target_y)/200. plt.text(1.5, -4, 'Accuracy=%.2f' % accuracy, fontdict={'size': 20, 'color': 'red'}) plt.pause(0.1) diff --git a/tutorial-contents/401_CNN.py b/tutorial-contents/401_CNN.py index 1844267..6602e6a 100644 --- a/tutorial-contents/401_CNN.py +++ b/tutorial-contents/401_CNN.py @@ -98,7 +98,7 @@ for epoch in range(EPOCH): if step % 50 == 0: test_output = cnn(test_x) pred_y = torch.max(test_output, 1)[1].data.squeeze() - accuracy = sum(pred_y == test_y) / test_y.size(0) + accuracy = sum(pred_y == test_y) / float(test_y.size(0)) print('Epoch: ', epoch, '| train loss: %.4f' % loss.data[0], '| test accuracy: %.2f' % accuracy) diff --git a/tutorial-contents/402_RNN_classifier.py b/tutorial-contents/402_RNN_classifier.py index 1909387..909481a 100644 --- a/tutorial-contents/402_RNN_classifier.py +++ b/tutorial-contents/402_RNN_classifier.py @@ -97,7 +97,7 @@ for epoch in range(EPOCH): if step % 50 == 0: test_output = rnn(test_x) # (samples, time_step, input_size) pred_y = torch.max(test_output, 1)[1].data.numpy().squeeze() - accuracy = sum(pred_y == test_y) / test_y.size + accuracy = sum(pred_y == test_y) / float(test_y.size) print('Epoch: ', epoch, '| train loss: %.4f' % loss.data[0], '| test accuracy: %.2f' % accuracy) # print 10 predictions from test data