试图预测预测值大于0.5,它将是正预测(1),低于0.5值为0,但在循环中存在问题

发布于 2025-02-13 05:17:51 字数 767 浏览 0 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2025-02-20 05:17:51

似乎您应该使用y_pred [0] [i]。该数组看起来只有一个子数组,因此应使用[0] [i]。另外,如果代码正是编写的,我认为

y_pred ( for i in range(len(y_pred)):

应该是

for i in range(len(y_pred)):

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

y_pred ( for i in range(len(y_pred)):

should be

for i in range(len(y_pred)):
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文