3. Developing a Text Classifier
Activity 3.01: Developing End-to-End Text Classifiers
Solution
The following steps will help you implement this activity:
- Open a Jupyter Notebook.
- Insert a new cell and add the following code to import the necessary packages:
import pandas as pd import seaborn as sns import matplotlib.pyplot as plt %matplotlib inline from nltk import word_tokenize from nltk.corpus import stopwords from nltk.stem import WordNetLemmatizer from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.model_selection import train_test_split import nltk nltk.download('stopwords') nltk.download('punkt') nltk.download('wordnet') import warnings import string import re warnings.filterwarnings('ignore') from sklearn.metrics import accuracy_score, roc_curve, \ classification_report, confusion_matrix, \ precision_recall_curve, auc
- Read a data file. It has three columns:
is_political
,headline
, andshort_description...