"""
## importing Libraries 
"""
import numpy as np 
import matplotlib.pyplot as plt 
import pandas as pd
import seaborn as sns 
"""
## Importing dataset
"""
dataset =pd.read_csv('../input/spam-mails-dataset/spam_ham_dataset.csv')

dataset.head(10)
dataset.tail(10)
dataset.describe()
dataset.shape
dataset.info()
spam = dataset[dataset['label_num'] == 0]
spam
ham = dataset[dataset['label_num']==1]
ham
sns.countplot(dataset['label_num'])
from sklearn.feature_extraction.text import CountVectorizer
vectorizer = CountVectorizer()
spam_ham = vectorizer.fit_transform(dataset['text'])
print(spam_ham.toarray())
spam_ham.shape
X= spam_ham
Y= dataset['label_num'].values
print(Y)
"""
## Spliting data into train_set and test_set
"""
from sklearn.model_selection import train_test_split
X_train , X_test , Y_train , Y_test =train_test_split(X, Y, test_size = 0.2, random_state = 42)
"""
## train NAIVE_BAYES algorithm
"""
from sklearn.naive_bayes import MultinomialNB
NB_classifier =MultinomialNB()
NB_classifier.fit(X_train , Y_train)
"""
## predicting Training_set result 
"""
Y_pred_train = NB_classifier.predict(X_train)
print(Y_pred_train)
"""
## Predicting Testset_result
"""
Y_pred_test = NB_classifier.predict(X_test)
print(Y_pred_test)
from sklearn.metrics import classification_report , confusion_matrix , accuracy_score
cm_test = confusion_matrix(Y_test, Y_pred_test)
cm_train = confusion_matrix(Y_train , Y_pred_train)

print(cm_test)
print(cm_train)
sns.heatmap(cm_train , annot = True)
sns.heatmap(cm_test, annot = True)
"""
## Accuracy score of test set 
"""
accuracy_score(Y_test , Y_pred_test)
print(classification_report(Y_pred_test, Y_test))