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.
Deze oefening maakt deel uit van de cursus
Linear Classifiers in Python
Oefeninstructies
- 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?
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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, ____)