spamTesting, spamTrain = train_test_split(
    data, test_size=0.8, random_state=5)

len(spamTesting)

len(spamTrain)

"""
Explanation: We will first break out a training and testing set with an 80/20 split
End of explanation
"""


RndForClf = RandomForestClassifier(n_jobs=2, n_estimators=100, max_features="auto",random_state=620)

RndForPred = RndForClf.fit(spamTrain[names[0:57]],spamTrain[names[-1]]).predict(spamTesting[names[0:57]])

accuracy_score(spamTesting[names[-1]], RndForPred)

print(classification_report(spamTesting[names[-1]], RndForPred,target_names=['Not Spam','Spam']))

"""
Explanation: Random Forests
End of explanation
"""


AdaBooClf = AdaBoostClassifier()

AdaBooPred = AdaBooClf.fit(spamTrain[names[0:57]],spamTrain[names[-1]]).predict(spamTesting[names[0:57]])

accuracy_score(spamTesting[names[-1]], AdaBooPred)

print(classification_report(spamTesting[names[-1]], AdaBooPred,target_names=['Not Spam','Spam']))

"""
Explanation: A 94% accuracy with an 95% Precision - recall - f1score is quite high, but how does it compare to other methods?
Ada Boost
End of explanation
"""


KNNClf = KNeighborsClassifier(7)

KNNPred = KNNClf.fit(spamTrain[names[0:57]],spamTrain[names[-1]]).predict(spamTesting[names[0:57]])

accuracy_score(spamTesting[names[-1]], KNNPred)

print(classification_report(spamTesting[names[-1]], KNNPred,target_names=['Not Spam','Spam']))

"""
Explanation: The scores are just slightly worse than the Random Forest
K-nearest neighbors
End of explanation
"""


#RBF
SVMRBFClf = SVC()

SVMRBFPred = SVMRBFClf.fit(spamTrain[names[0:57]],spamTrain[names[-1]]).predict(spamTesting[names[0:57]])

accuracy_score(spamTesting[names[-1]], SVMRBFPred)

print(classification_report(spamTesting[names[-1]], SVMRBFPred,target_names=['Not Spam','Spam']))

"""
Explanation: Very poor performance compared to the previous two.  Also, so far it seems that the methods have a better performance identifying Non-spam than spam as noted by the lower precision, recall and f1 scores
Support Vector Machines
End of explanation
"""


GaussClf = GaussianNB()

GaussPred = GaussClf.fit(spamTrain[names[0:57]],spamTrain[names[-1]]).predict(spamTesting[names[0:57]])

accuracy_score(spamTesting[names[-1]], GaussPred)

print(classification_report(spamTesting[names[-1]], GaussPred,target_names=['Not Spam','Spam']))

"""
Explanation: Not great performance either
Naive Bayes
End of explanation
"""


DecTreeClf = DecisionTreeClassifier(random_state=620)

DecTreePred = DecTreeClf.fit(spamTrain[names[0:57]],spamTrain[names[-1]]).predict(spamTesting[names[0:57]])

accuracy_score(spamTesting[names[-1]], DecTreePred)

print(classification_report(spamTesting[names[-1]], GaussPred,target_names=['Not Spam','Spam']))

"""
Explanation: Also not great performance either
Decision Trees
End of explanation
"""


VotingHardClf = VotingClassifier(estimators = [('RF',RndForClf),('Ada',AdaBooClf),('KNN',KNNClf),('SVNRBF',SVMRBFClf),('NB',GaussClf),('DecTree',DecTreeClf)],voting = 'hard')

VotingHardPred = VotingHardClf.fit(spamTrain[names[0:57]],spamTrain[names[-1]]).predict(spamTesting[names[0:57]])

accuracy_score(spamTesting[names[-1]], VotingHardPred)

print(classification_report(spamTesting[names[-1]], VotingHardPred,target_names=['Not Spam','Spam']))

"""
Explanation: Decision tree is decent, though not as good as the Random Forest
So the Random Forest is the best model for Spam detection, but most models seems to have poor precision when it comes to Spam and poor recall when it comes to non-spam
We can use all the models to create one voting model to try and increase the accuracy.
End of explanation
"""


