如何在 Pytorch 中找到神经网络的测试准确性。如何制定将预测与数据进行比较的方程
我无法确定测试数据的准确性。我是 pytorch 的新手,每次迭代的准确度都是 0。测试和训练损失值是合理的,并且随着迭代的进行而改进。但是,我不确定我是否评估了错误数据的准确性。我正在使用预测数据和 test_target 数据。 test_input 被输入到模型中以生成预测。一旦我理解了这一部分,我就能够找到训练的准确性。
for e in range(num_epochs):
optimizer.zero_grad()
out = model(train_input)
loss = loss_fn(out, train_target)
loss.backward()
optimizer.step()
with torch.no_grad():
pred = model(train_input, future_preds=future)
training_loss = loss_fn(pred[:,:-future], train_target)
train_loss.append(training_loss)
pred = model(test_input, future_preds=future)
test_loss = loss_fn(pred[:,:-future], test_target)
testing_loss.append(test_loss)
predictions = pred.detach().numpy()
testing_accu= sum(pred[:,:-future]==test_target)/20
test_accu.append(testing_accu)
print("Testing Accuracy: ", ((pred[:,:-future] > 0.5) == test_target).float().mean().item())
return testing_loss, train_loss, test_accu
我的数据的tensor.shape是:
train_input : (80,999)
train_target: (80,999)
test_input : (20,999)
test_target : (20,999)
I am having trouble finding the accuracy of my testing data. I am new in pytorch and keep getting an accuracy of 0 for every iteration. Testing and training loss values are reasonable and they improve as the iterations go on. However, I am not sure if I am evaluating the wrong data for the accuracy. I am using the predicted data and the test_target data. The test_input is feed into the model to generate the predictions. Once I can understand this part I will able to find also the training accuracy.
for e in range(num_epochs):
optimizer.zero_grad()
out = model(train_input)
loss = loss_fn(out, train_target)
loss.backward()
optimizer.step()
with torch.no_grad():
pred = model(train_input, future_preds=future)
training_loss = loss_fn(pred[:,:-future], train_target)
train_loss.append(training_loss)
pred = model(test_input, future_preds=future)
test_loss = loss_fn(pred[:,:-future], test_target)
testing_loss.append(test_loss)
predictions = pred.detach().numpy()
testing_accu= sum(pred[:,:-future]==test_target)/20
test_accu.append(testing_accu)
print("Testing Accuracy: ", ((pred[:,:-future] > 0.5) == test_target).float().mean().item())
return testing_loss, train_loss, test_accu
The tensor.shape for my data is:
train_input : (80,999)
train_target: (80,999)
test_input : (20,999)
test_target : (20,999)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论