Visualizing multi-class logistic regression
In this exercise we'll continue with the two types of multi-class logistic regression, but on a toy 2D data set specifically designed to break the one-vs-rest scheme.
The data set is loaded into X_train
and y_train
. The two logistic regression objects,lr_mn
and lr_ovr
, are already instantiated (with C=100
), fit, and plotted.
Notice that lr_ovr
never predicts the dark blue class… yikes! Let's explore why this happens by plotting one of the binary classifiers that it's using behind the scenes.
Cet exercice fait partie du cours
Linear Classifiers in Python
Instructions
- Create a new logistic regression object (also with
C=100
) to be used for binary classification. - Visualize this binary classifier with
plot_classifier
… does it look reasonable?
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Print training accuracies
print("Softmax training accuracy:", lr_mn.score(X_train, y_train))
print("One-vs-rest training accuracy:", lr_ovr.score(X_train, y_train))
# Create the binary classifier (class 1 vs. rest)
lr_class_1 = ____
lr_class_1.fit(X_train, y_train==1)
# Plot the binary classifier (class 1 vs. rest)
plot_classifier(X_train, y_train==1, ____)