How Often Right
logits has one row per example and one column per class. The predicted class of an example is the column with its highest score. labels holds the right classes. Return the accuracy: the share of examples predicted right, from 0 to 1.
Example 1
logits [[0.1,0.9],[0.8,0.2],[0.3,0.7]]
labels [1,0,0]
returns 0.6666667
Constraints
- 1 to 6 examples, 2 to 4 classes
- No row has two equal highest scores
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More PyTorch problems
- In BatchesMedium
- Many OutputsMedium
- Mean Squared ErrorMedium
- One Step DownhillMedium
- Two LayersMedium
- Two ParametersMedium
- Unit RowsMedium
- A Tiny NetworkHard