text_html_output_1.png
from nltk.corpus import stopwords

from sklearn.feature_extraction.text import CountVectorizer

from sklearn.feature_extraction.text import TfidfTransformer

from sklearn.naive_bayes import MultinomialNB

from sklearn.pipeline import Pipeline

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import string

messages = pd.read_csv('../input/spam.csv', encoding='latin-1')

messages.drop(['Unnamed: 2', 'Unnamed: 3', 'Unnamed: 4'], axis=1, inplace=True)

messages = messages.rename(columns={'v1': 'class', 'v2': 'text'})

def process_text(text):
    nopunc = [char for char in text if char not in string.punctuation]
    nopunc = ''.join(nopunc)
    clean_words = [w for w in nopunc.split() if w.lower() not in stopwords.words('english')]
    return clean_words
messages['text'].apply(process_text).head()

pipeline = Pipeline([('bow', CountVectorizer(analyzer=process_text)), ('tfidf', TfidfTransformer()), ('classifier', MultinomialNB())])

pipeline.fit(X_train, y_train)