Training a logistic regression model with scikit-learn

来源:互联网 发布:网络作家富豪榜2011 编辑:程序博客网 时间:2024/05/17 22:43

1. Since scikit-learn implements a highly optimized version oflogistic regression that also supports multiclass settings off-the-shelf, we will skip the implementation and use the sklearn.linear_model.LogisticRegressionclass 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》

0 0