In [1]:
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split as tts
from yellowbrick.classifier import ConfusionMatrix
In [2]:
iris = load_iris()
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = tts(X, y, test_size=0.2)
In [3]:
## target names are a list of strings corresponding to the classes
classes = iris.target_names
classes
Out[3]:
In [4]:
model = LogisticRegression()
cm = ConfusionMatrix(model, classes=classes)
cm.fit(X_train, y_train)
cm.score(X_test, y_test)
cm.show()
:(
Workaround:
In [5]:
cm = ConfusionMatrix(
model, classes=classes,
label_encoder={0: 'setosa', 1: 'versicolor', 2: 'virginica'}
)
cm.fit(X_train, y_train)
cm.score(X_test, y_test)
cm.show()
In [ ]: