ConfusionMatrix classes: one label must be specified in y true.
See original GitHub issueWhen trying to passes class names to the ConfusionMatrix, I’m getting the following error:
/usr/local/lib/python3.6/site-packages/sklearn/metrics/classification.py:248: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if np.all([l not in y_true for l in labels]):
Traceback (most recent call last):
File "rc.py", line 63, in <module>
viz.score(X_test, y_test)
File "/Users/benjamin/Repos/ddl/yellowbrick/yellowbrick/classifier/confusion_matrix.py", line 107, in score
y, y_pred, labels=self.classes_, sample_weight=sample_weight
File "/usr/local/lib/python3.6/site-packages/sklearn/metrics/classification.py", line 249, in confusion_matrix
raise ValueError("At least one label specified must be in y_true")
ValueError: At least one label specified must be in y_true
This is do to the fact that the y_true vector is label encoded (e.g. ones and zeros) but that the labels are strings, e.g. “occupied” and “unoccupied”.
Here is the code to produce the error:
df = pd.read_csv('examples/data/occupancy/occupancy.csv')
features = ["temperature", "relative humidity", "light", "C02", "humidity"]
target = "occupancy"
X = df[features]
y = df[target]
classes = ["unoccupied", "occupied"]
X_train, X_test, y_train, y_test = tts(X, y, test_size=0.2)
viz = ConfusionMatrix(MultinomialNB(), classes=classes)
viz.fit(X_train, y_train)
viz.score(X_test, y_test)
viz.poof()
Note that:
viz = ConfusionMatrix(MultinomialNB())
Does not raise an exception.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
At least one label specified must be in y_true, target vector is ...
I checked this question which was like mine and I changed the y from categorical to numerical but the error is still there!...
Read more >How to pass class names to ConfusionMatrix
This is a follow up to issue #244 and PR #253, to document how to pass class names ... is None: ValueError: At...
Read more >sklearn.metrics.ConfusionMatrixDisplay
class sklearn.metrics. ... If None, display labels are set from 0 to n_classes - 1 . ... Plot the confusion matrix given the...
Read more >Understanding Confusion Matrix | by Sarang Narkhede
Well, it is a performance measurement for machine learning classification problem where output can be two or more classes. It is a table...
Read more >Confusion Matrix — Yellowbrick v0.5 文档
The ConfusionMatrix visualizer is a ScoreVisualizer that takes a fitted ... If the X and y datasets have been encoded prior to training...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bbengfort Is anyone working on this bug yet? I was able to reproduce the error last night on my local environment and wanted to offer my help.
@rebeccabilbro yep, sorry about this, it should have been closed on June 8 with #253. For future reference, the fix to this is as follows:
Where the
label_encoder
argument can be asklearn.preprocessing.LabelEncoder
(or really anything withinverse_transform
that does the mapping) or adict
.closed via ff10ca0