Using SVMs for supervised text classification
In this recipe, we will build a machine learning classifier that uses the SVM algorithm. By the end of the recipe, you will have a working classifier that you will be able to test on new inputs and evaluate using the same classification_report
tools as we used in the previous sections.
Getting ready
We will continue working with the same packages that we already installed in the previous recipes.
How to do it…
We will start with the already familiar steps of dividing data into training and testing sets and creating a vectorizer. We will then train the SVM classifier and evaluate it.
Your steps are as follows:
- Import the necessary functions and packages:
import numpy as np import pandas as pd import string import pickle from sklearn import svm from sklearn import preprocessing from sklearn.metrics import classification_report from sklearn.model_selection import train_test_split from sklearn.feature_extraction...