<jupyter_start><jupyter_text><jupyter_code>import pandas as pd
import numpy as np
with open('/content/drive/MyDrive/SMSSpamCollection.txt') as f:
  lines = f.readlines()
labels = []
for line in lines:
  temp = line.split('\t')
  labels.append([temp[0],temp[1].strip()])
nlabels = np.array(labels)
import string
string.punctuation
text = []
for i in nlabels[:,1]:
  loweri = i.lower()
  out = ''.join([j for j in loweri if j not in string.punctuation])
  text.append(out)
  
len(text)
nlabels.shape
labels = nlabels[:,0]
labels
labels.shape
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
X = vectorizer.fit_transform(text)
vectorizer.get_feature_names_out()
X_train, X_test, y_train, y_test = train_test_split(X, labels, test_size=0.33, random_state=42)
x_train = X_train.toarray()
x_test = X_test.toarray()
from sklearn.naive_bayes import GaussianNB<jupyter_output><empty_output><jupyter_text><jupyter_code>gnb = GaussianNB()
y_t = gnb.fit(x_train, y_train)
y_pred = y_t.predict(x_test)
(y_test == y_pred).sum()
print(f'{(y_test == y_pred).sum()/len(y_test) * 100:0.2f}% correct')
from sklearn.metrics import classification_report
print(classification_report(y_test,y_pred))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13297463489623368, 'fraction_numerical': 0.010760953112990008, 'mean_word_length': 6.75, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '350262', 'license': 'MIT', 'n_tokens_mistral': 497, 'n_tokens_neox': 487, 'n_words': 98, 'path': 'Manning_Intro2Pytorch.ipynb', 'repo_name': 'cjsutton77/BrushingUpOnC', 'size': '1301'}