text_html_output_1.png
from nltk.corpus import stopwords

from sklearn.feature_extraction.text import CountVectorizer

import pandas as pd

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'})

messages.groupby('class').describe()

def process_text(text):
    """
    What will be covered:
    1. Remove punctuation
    2. Remove stopwords
    3. Return list of clean text words
    """
    nopunc = [char for char in text if char not in string.punctuation]
    nopunc = ''.join(nopunc)
    clean_words = [word for word in nopunc.split() if word.lower() not in stopwords.words('english')]
    return clean_words

bow_transformer = CountVectorizer(analyzer=process_text).fit(messages['text'])

len(bow_transformer.vocabulary_)

messages_bow = bow_transformer.transform(messages['text'])

print('Sparse matrix shape ', messages_bow.shape)
print('Amount of Non-Zero occurences: ', messages_bow.nnz)