Professional Documents
Culture Documents
Exp-9 - Jupyter Notebook
Exp-9 - Jupyter Notebook
In [12]:
import numpy as np
import pandas as pd
from collections import Counter
In [13]:
data = pd.read_csv('./data/spam.csv')
data = data[['v1', 'v2']]
data.head()
Out[13]:
v1 v2
In [14]:
data = data.sample(frac=1)
train, test = data[:4000], data[4000:]
X_train, X_test, y_train, y_test = train['v2'], test['v2'], train['v1'], test['v1']
In [15]:
Out[15]:
In [16]:
vocab_spam = Counter()
for i in train[train['v1'] == 'spam']['v2']:
vocab_spam += Counter(i.split(' '))
vocab_ham = Counter()
for i in train[train['v1'] == 'ham']['v2']:
vocab_ham += Counter(i.split(' '))
In [17]:
localhost:8888/notebooks/Exp-9.ipynb 1/2
5/23/22, 8:08 PM Exp-9 - Jupyter Notebook
In [18]:
In [22]:
if label == pred:
if label == 'spam':
d['TP'] += 1
else:
d['TN'] += 1
else:
if label == 'spam':
d['FP'] += 1
else:
d['FN'] += 1
In [29]:
Accuracy: 0.8810432569974554
Precision: 0.9808612440191388
Recall: 0.5283505154639175
In [ ]:
localhost:8888/notebooks/Exp-9.ipynb 2/2