A recycling plant's camera looks at each item on the belt and gives it a score for every bin — the higher the score, the more the item looks like it belongs in that bin. The scores arrive laid out like X in this chapter: one row per item (a sample), one column per bin. The bins are the classes the camera chooses between.
The camera's call for an item is the class whose column holds that row's highest score. NumPy has a tool for this: np.argmax gives the position of the largest value instead of the value itself, and, like max, it takes an axis.
Task: write classify(scores, classes, actual) returning a tuple (calls, accuracy):
calls — the camera's call for each item, as class names, in item order;accuracy — the share of items whose call matches actual (the bin a person says each item really belongs in), rounded to 4 decimal places.If two columns tie for a row's highest score, the call is whichever comes first in classes — exactly what np.argmax does.
Example
Item 1's highest score is 1.7, in the plastic column, but a person put it in metal — so two calls out of three are right.
This move — one row of scores in, one class out — is how almost every classifier you'll meet later turns its numbers into an answer.