<jupyter_start><jupyter_text>Now we will use a CountVectorizer to split up each message into its list of words, and throw that into a MultinomialNB classifier. Call fit() and we've got a trained spam filter ready to go! It's just that easy.<jupyter_code>vectorizer = CountVectorizer()
counts = vectorizer.fit_transform(data['message'].values)
print(counts)
targets = data['class'].values
# print(targets)
classifier = MultinomialNB()
classifier.fit(counts, targets)
# print(data['message'].shape)
# print(counts.shape)
# data['message'][0]
# print(counts[0])
examples = ["Hi raj", "Free chatting offer raj","Free Free Viagra now Fight The Risk of Cancer!"]
example_counts = vectorizer.transform(examples)
print(example_counts)
predictions = classifier.predict(example_counts)
predictions<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11505507955936352, 'fraction_numerical': 0.0024479804161566705, 'mean_word_length': 7.43298969072165, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '561038', 'license': 'MIT', 'n_tokens_mistral': 265, 'n_tokens_neox': 250, 'n_words': 75, 'path': '12. Naive Bayes Algo.ipynb', 'repo_name': 'therajmaurya/Machine-Learning-Workshop-Content', 'size': '817'}