Logistic Regression in Python - Building Classifier


Advertisements

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

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.

Advertisements