October 2018
Intermediate to advanced
252 pages
6h 49m
English
Following is the full code listing of the recipe Classification for spam detection:
from keras.layers import Embedding, Dense, LSTMfrom keras.models import Sequentialfrom keras.preprocessing.text import Tokenizerfrom keras.preprocessing.sequence import pad_sequencesimport numpy as npfrom sklearn.metrics import confusion_matriximport pandas as pd# get datasetdata = pd.read_csv('/spam-detection/spam_dataset.csv')texts = []classes = []for i, label in enumerate(data['Class']): texts.append(data['Text'][i]) if label == 'ham': classes.append(0) else: classes.append(1)texts = np.asarray(texts)classes = np.asarray(classes)print("number of texts :", len(texts))print("number of labels: ", len(classes))# number of words used as features ...