Logistic Regression In Python 简明教程
Logistic Regression in Python - Building Classifier
你不需要从头构建分类器。构建分类器很复杂,需要具备多个领域的知识,例如统计学、概率论、优化技术等等。市场上有几个预先构建的库,它们有经过充分测试的高效分类器实现。我们将使用 sklearn 中的一个这样的预先构建的模型。
It is not required that you have to build the classifier from scratch. Building classifiers is complex and requires knowledge of several areas such as Statistics, probability theories, optimization techniques, and so on. There are several pre-built libraries available in the market which have a fully-tested and very efficient implementation of these classifiers. We will use one such pre-built model from the sklearn.
The sklearn Classifier
从 sklearn 工具箱创建逻辑回归分类器非常简单,只需像这里所示的那样用一个程序语句完成 −
Creating the Logistic Regression classifier from sklearn toolkit is trivial and is done in a single program statement as shown here −
In [22]: classifier = LogisticRegression(solver='lbfgs',random_state=0)
创建分类器后,你将把你训练的数据输入到分类器中,这样它可以调整其内部参数,并准备好对你的未来数据进行预测。为了调整分类器,我们运行以下语句 −
Once the classifier is created, you will feed your training data into the classifier so that it can tune its internal parameters and be ready for the predictions on your future data. To tune the classifier, we run the following statement −
In [23]: classifier.fit(X_train, Y_train)
分类器现在准备好了进行测试。以下代码是上面两个语句执行的输出 −
The classifier is now ready for testing. The following code is the output of execution of the above two statements −
Out[23]: LogisticRegression(C = 1.0, class_weight = None, dual = False,
fit_intercept=True, intercept_scaling=1, max_iter=100,
multi_class='warn', n_jobs=None, penalty='l2', random_state=0,
solver='lbfgs', tol=0.0001, verbose=0, warm_start=False))
现在,我们准备测试创建的分类器。我们将在下一章中处理这个问题。
Now, we are ready to test the created classifier. We will deal this in the next chapter.