<jupyter_start><jupyter_text>Load Titanic Dataset<jupyter_code>df = pd.read_csv('spam.csv')
df.head()
df.groupby('Category').describe()<jupyter_output><empty_output><jupyter_text>Preprocessing<jupyter_code>df['spam'] = df.Category.apply(lambda x:1 if x=='spam' else 0)
df.head()<jupyter_output><empty_output><jupyter_text>Split into Input, Target<jupyter_code>inputs = df.iloc[:, 1]
target = df.iloc[:, -1]<jupyter_output><empty_output><jupyter_text>Train, Test Split<jupyter_code>from sklearn.model_selection import train_test_split

x_train, x_test, y_train, y_test = train_test_split(inputs, target, test_size=0.2)<jupyter_output><empty_output><jupyter_text>Count Vectorizer of Text<jupyter_code>from sklearn.feature_extraction.text import CountVectorizer

cv = CountVectorizer()

x_train_counts = cv.fit_transform(x_train.values)
x_train_counts.toarray()[:3]<jupyter_output><empty_output><jupyter_text>Naive Bayes (Multinomial)<jupyter_code>from sklearn.naive_bayes import MultinomialNB

mnb = MultinomialNB()
mnb.fit(x_train_counts, y_train)
x_test_count = cv.transform(x_test)

mnb.score(x_test_count, y_test)<jupyter_output><empty_output><jupyter_text>PipeLine<jupyter_code>from sklearn.pipeline import Pipeline

clf = Pipeline([
    ('vectorizer', CountVectorizer()),
    ('nb', MultinomialNB())
])

clf.fit(x_train, y_train)
clf.score(x_test, y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13102951763858892, 'fraction_numerical': 0.005039596832253419, 'mean_word_length': 10.487603305785123, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '221951', 'license': 'Apache-2.0', 'n_tokens_mistral': 568, 'n_tokens_neox': 551, 'n_words': 70, 'path': '13_Naive_Bayes_Classifier/Naive_Bayes_Email_Spam.ipynb', 'repo_name': 'Yeasmin-Tasnima/ML', 'size': '1389'}