Why does my code not throw an error message when I use variables within a def
that are defined outside of the function?
import numpy as np
y_model=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,1,1
,0,0,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1]
y_test=[0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0
,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,1,0,1,0,0,1,0,0,0,0,1
,0,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,1
,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,1]
def return_recall_and_precision(y_predict,y_actual):
import numpy as np
# get array of matches
TP=(y_model==y_test) # Shouldnt this thrown an exception error? y_model is not in the local # scope
print("tp is",TP)
TP=np.sum(TP)
return TP
TP=return_recall_and_precision(y_model,y_test)
print(TP)