What does np.mean(y_pred==y_test) mean?

Asked 2 years ago, Updated 2 years ago, 23 views

np.mean(y_pred==y_test)

I understand that the above np.mean is the arithmetic average, but what does == mean?

python

2022-09-30 19:57

1 Answers

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.


2022-09-30 19:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.