Logistic regression

Let's now simply replicate the simple logistic regression we did in Chapter 1, Getting Started with Text Classification, but on our custom dataset, as follows:

from sklearn.linear_model import LogisticRegression as LRlr_clf = Pipeline([('vect', CountVectorizer()), ('tfidf', TfidfTransformer()), ('clf',LR())])

As you can see in the preceding snippet, lr_clf becomes our classifier pipeline. We saw the pipeline in our introductory section. A pipeline allows us to queue multiple operations in one single Python object.

We are able to call functions such as fit, predict, and fit_transform on our Pipeline objects because a pipeline automatically calls the corresponding function of the last component in the list. 
lr_clf.fit(X=X_train, ...

Get Natural Language Processing with Python Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.