<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Naive Bayes classification example from the book "Principles of Data Science"
P(spam|&lt;sentence&gt;) = P(&lt;sentence&gt;|spam) * P(spam) / P(&lt;sentence&gt;)
P(non-spam|&lt;sentence&gt;) = P(&lt;sentence&gt;|non-spam) * P(non-spam) / P(&lt;sentence&gt;)
Step1:  Use the built-in library methods
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
import sklearn
df = pd.read_table('https://raw.githubusercontent.com/sinanuozdemir/sfdat22/master/data/sms.tsv', sep='\t', header=None, names=['label', 'msg'])
df
df.label.value_counts()
value_probablity = df.label.value_counts()/len(df)
spam_probability = value_probablity.spam
ham_probability = value_probablity.ham
print('spam probability: {}, ham probability: {}'.format(spam_probability, ham_probability))
spams = df[df.label == 'spam']
sentence = 'send cash now'
spam_words_probability = 1
for word in sentence.split():
    word_probability = spams[spams.msg.str.contains(word)].shape[0]/float(spams.shape[0])
    print("word {} probability: {}".format(word, word_probability))
    spam_words_probability *= word_probability
spam_words_probability *= spam_probability
print('spam words probability: {}'.format(spam_words_probability))
hams = df[df.label == 'ham']
sentence = 'send cash now'
ham_words_probability = 1
for word in sentence.split():
    word_probability = hams[hams.msg.str.contains(word)].shape[0]/float(hams.shape[0])
    print("word {} probability: {}".format(word, word_probability))
    ham_words_probability *= word_probability
ham_words_probability *= ham_probability
print('ham words probability: {}'.format(ham_words_probability))
if spam_words_probability > ham_words_probability:
    print('{} is more likely a spam'.format(sentence))
else:
    print('{} is more likely NOT a spam'.format(sentence))
Explanation: Naive Bayes classification example from the book "Principles of Data Science"
P(spam|&lt;sentence&gt;) = P(&lt;sentence&gt;|spam) * P(spam) / P(&lt;sentence&gt;)
P(non-spam|&lt;sentence&gt;) = P(&lt;sentence&gt;|non-spam) * P(non-spam) / P(&lt;sentence&gt;)
End of explanation
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
x_train, x_test, y_train, y_test = train_test_split(df.msg, df.label, random_state=1)
vect = CountVectorizer()
train_dtm = vect.fit_transform(x_train)
test_dtm = vect.transform(x_test)
nb = MultinomialNB()
nb.fit(train_dtm, y_train)
predicts = nb.predict(test_dtm)
predicts
from sklearn import metrics
print('accuracy: {}, confusion matrix: {}'
      .format(metrics.accuracy_score(y_test, predicts), metrics.confusion_matrix(y_test, predicts)))
Explanation: Use the built-in library methods
End of explanation
<END_TASK>