# Trying to predict, prediction value greater than 0.5 it will be positive prediction (1) , under 0.5 value as 0 ,negative , but having problem in loop

## Issue

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
accuracy = result
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.5:
y_pred[i] = int(1)
else:
y_pred[i] = 0

print(y_pred) )
``````

error is : invalid syntax .

can anyone help to sort out this one ?

## Solution

Seems like you should use y_pred[i]. The array looks to be 2d with only one sub array, so [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)):
`````` 