Fitting multi-class logistic regression
In this exercise, you'll fit the two types of multi-class logistic regression, one-vs-rest and softmax/multinomial, on the handwritten digits data set and compare the results. The handwritten digits dataset is already loaded and split into X_train, y_train, X_test, and y_test.
Cet exercice fait partie du cours
Linear Classifiers in Python
Instructions
- Fit a one-vs-rest logistic regression classifier by setting the
multi_classparameter and report the results. - Fit a multinomial logistic regression classifier by setting the
multi_classparameter and report the results.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Fit one-vs-rest logistic regression classifier
lr_ovr = ____
lr_ovr.fit(X_train, y_train)
print("OVR training accuracy:", lr_ovr.score(X_train, y_train))
print("OVR test accuracy :", lr_ovr.score(X_test, y_test))
# Fit softmax classifier
lr_mn = ____
lr_mn.fit(X_train, y_train)
print("Softmax training accuracy:", lr_mn.score(X_train, y_train))
print("Softmax test accuracy :", lr_mn.score(X_test, y_test))