The notes suggest that the classification (y hat) can be converted to an integer value in one line. I can’t see how to do this so compactly.
I’ve reused working code from the last assignment but although the output is OK I get an error: “predictions referenced before assignment”. The variable predictions is defined in an assignment statement. As far as I know Python creates variables when they are assigned a value. Please advise how to fix this.
See code below:
parameters, t_X = predict_test_case()
predictions = predict(parameters, t_X)
print("Predictions: " + str(predictions))
predict_test(predict)
UnboundLocalError Traceback (most recent call last)
in
1 parameters, t_X = predict_test_case()
2
----> 3 predictions = predict(parameters, t_X)
4 print("Predictions: " + str(predictions))
5
in predict(parameters, X)
28
29 if A2[0, i] > 0.5 :
—> 30 predictions[0,i] = …
31 else:
32 predictions[0,i] = …
UnboundLocalError: local variable ‘predictions’ referenced before assignment