Issue
I am having a hard time understanding why the results are not the same for following code.
I am trying to find the accuracy of a model but the first item gives a result of tensor(66.), and second item gives a result of tensor(105).
(y_test[y_test==y_predicted_cls].sum(), y_predicted_cls.eq(y_test).sum())
Both of the tensors (y_test and y_predicted_cls) have the same data type, torch.float32. Output:
(tensor(66.), tensor(105))
I thought that first one would be equal to the second one.
Solution
The statement y_test[y_test==y_predicted_cls].sum()
gives the sum for the y_test
list/array while, y_predicted_cls.eq(y_test).sum()
gives the sum for y_predicted_cls
, and in the first case, if both the arrays are same, it yields:
y_test[1].sum()
else :
y_test[0].sum()
Answered By - Roshin Raphel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.