np.mean(y_pred==y_test)
I understand that the above np.mean is the arithmetic average, but what does == mean?
python
y_pred==y_test
performs element-by-element comparisons in the y_pred and y_test arrays and returns a boolean array of the same size.
Only if y_pred and y_test are the same size
np.mean()
takes the average of all elements when axis
is not specified, so
np.mean(y_pred==y_test)
takes the mean of the boolean array comparing the two arrays above.
Since true
is calculated as 1
and false
is calculated as 0
, the result is to compare the two arrays to calculate the establishment where the elements match.
© 2024 OneMinuteCode. All rights reserved.