试图预测预测值大于0.5,它将是正预测(1),低于0.5值为0,但在循环中存在问题
训练模型后,评估dtype = float32上的预测。
y_pred = model.predict(x_test)
y_pred
array([[0.952564 ],
[0.40119413],
[0.8223132 ],
...,
[0.03289893],
[0.16677496],
[0.882395 ]], dtype=float32)
result = model.evaluate(np.asarray(x_test), np.asarray(y_test))
loss = result[0]
accuracy = result[1]
print(f"[+] Accuracy: {accuracy*100:.2f}%")
因此,为此,我有float32,但为正面& 0对于neg,为此,我有一些问题,所以我要这样做,将其float32到int32&一个循环,如果值大于0.5,则将其计为1&如果小于0.5,则计数为0表示负。 我尝试的循环:
y_pred = model.predict(x_test)
y_pred ( for i in range(len(y_pred)):
if y_pred[i][0] >= 0.5:
y_pred[i][0] = int(1)
else:
y_pred[i][0] = 0
print(y_pred[0]) )
错误是:无效语法。
谁能帮忙解决这个问题?
After training the model , evaluating prediction that is on dtype=float32.
y_pred = model.predict(x_test)
y_pred
array([[0.952564 ],
[0.40119413],
[0.8223132 ],
...,
[0.03289893],
[0.16677496],
[0.882395 ]], dtype=float32)
result = model.evaluate(np.asarray(x_test), np.asarray(y_test))
loss = result[0]
accuracy = result[1]
print(f"[+] Accuracy: {accuracy*100:.2f}%")
so , for this i have float32 but 1 for positive & 0 for neg, for this i have some issue , so i am trying to do, make it float32 to int32 & a loop that if value is greater than 0.5 then it will count as 1 & if less than 0.5 then count as 0 means neg.
the loop i tried :
y_pred = model.predict(x_test)
y_pred ( for i in range(len(y_pred)):
if y_pred[i][0] >= 0.5:
y_pred[i][0] = int(1)
else:
y_pred[i][0] = 0
print(y_pred[0]) )
error is : invalid syntax .
can anyone help to sort out this one ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎您应该使用y_pred [0] [i]。该数组看起来只有一个子数组,因此应使用[0] [i]。另外,如果代码正是编写的,我认为
应该是
Seems like you should use y_pred[0][i]. The array looks to be 2d with only one sub array, so [0][i] should be used. Also, if the code is exactly what is written, i think
should be