1. Since scikit-learn implements a highly optimized version of logistic regression that also supports multiclass settings off-the-shelf, we will skip the implementation and use the sklearn.linear_model.LogisticRegression class as well as the familiar fit method to train the model:
from sklearn.linear_model import LogisticRegression
lr = LogisticRegression(C=1000.0, random_state=0) lr.fit(X_train_std, y_train)
2. Showing
plot_decision_regions(X_combined_std, y_combined, classifier=lr, test_idx=range(105, 150)) plt.xlabel('petal length [standardized]') plt.ylabel('petal width [standardized]') plt.legend(loc='upper left') plt.show()
Reference: 《Python Machine Learning》