I am doing a nano degree as a data analyst. So quite a green hand. In a hypothesis testing assignment I wrote this code:
Error_1 = 0
Error_2 = 0
Correct = 0
for x in jud_data['actual']:
y= jud_data['predicted']
if x == y :
Correct +=1,
elif x == 'innocent' & y == 'guilty' :
Error_1 += 0,
elif x == 'guilty' & y == 'innocent' :
Error_2 += 0,
print ('Error type 1 = ', Error_1)
print ('Error type 2 =', Error_2)
print ('Correct =', Correct)
I got this error message ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
What is wrong with this code? Knowing that the types of jud_data['actual'] and jud_data['predicted'] is object
Extra information:- I am using pandas
The Jud_data file looks like this
defendant_id actual predicted 0 22574 innocent innocent 1 35637 innocent innocent 2 39919 innocent innocent 3 29610 guilty guilty 4 38273 innocent innocent 5 24461 innocent innocent 6 34327 guilty guilty 7 33406 guilty guilty 8 21355 innocent innocent 9 36240 guilty guilty
我想计算1和2类错误。
我知道可能有其他方法可以做我想要的。但是,我想知道为什么这段代码不起作用。它应该工作......不是吗?
发布于 2018-09-10 12:56:53
Error_1 = 0
Error_2 = 0
Correct = 0
for x in jud_data['actual']:
y= jud_data['predicted']
if x == y :
Correct += 1
print ('Error type 1 = ', Error_1)
print ('Error type 2 =', Error_2)
print ('Correct =', Correct)
我不确定你的代码的意图。但是,如果我做对了,这似乎工作正常。
https://stackoverflow.com/questions/-100002597
复制相似问题