Add tests for single label binary pytorch models

Signed-off-by: abigailt <abigailt@il.ibm.com>
This commit is contained in:
abigailt 2024-05-02 14:46:08 +03:00
parent aa65f0f6f2
commit a8ec87f922
2 changed files with 170 additions and 42 deletions

View file

@ -235,7 +235,10 @@ class Model(metaclass=ABCMeta):
predicted = expit(predicted)
predicted[predicted < binary_threshold] = 0
predicted[predicted >= binary_threshold] = 1
return np.count_nonzero(y == predicted) / (predicted.shape[0] * y.shape[1])
if len(y.shape) > 1:
return np.count_nonzero(y == predicted) / (predicted.shape[0] * y.shape[1])
else:
return np.count_nonzero(y == predicted.reshape(-1)) / (predicted.shape[0])
else:
raise NotImplementedError('score method not implemented for output type: ', self.output_type)
else: