ValueError: Bad input shape for metric
7 Dec 2025
1 min read
ValueError: bad input shape for metric
$ python -c "from sklearn.metrics import precision_score; precision_score([[0],[1]], [[0],[1]])"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ValueError: Found input variables with inconsistent numbers of samples or shapes.
Why this happens
- Passing 2D arrays or mismatched shapes.
Fix
- Pass 1D arrays with same length.
Wrong code
precision_score([[0],[1]], [[0],[1]])
Fixed code
precision_score([0,1], [0,1])