#!/usr/bin/python

""" 
    This is the code to accompany the Lesson 1 (Naive Bayes) mini-project. 

    Use a Naive Bayes Classifier to identify emails by their authors
    
    authors and labels:
    Sara has label 0
    Chris has label 1
"""
import numpy as np
import sys
from time import time
sys.path.append("../tools/")
from email_preprocess import preprocess


### features_train and features_test are the features for the training
### and testing datasets, respectively
### labels_train and labels_test are the corresponding item labels
features_train, features_test, labels_train, labels_test = preprocess()



#########################################################
### your code goes here ###

from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
#t0 =time()
clf.fit(features_train,labels_train)
#print "training time:", round(time()-t0, 3), "s"

t1= time()
pred = clf.predict(features_test)
print "Prediction time:", round(time()-t1, 3), "s"
true_labels =[]
pred1 = np.array(pred)
test_labels1 = np.array(labels_test)
test = (pred1 == test_labels1)
#print "Truth",len(test)
for x in test:
    if x == True:
        true_labels.append(x)

print "Truth",len(true_labels)       
print "Predictive Truth",len(pred)

X = float(len(true_labels))
Y= float(len(pred))

print "Accuracy:",X/Y

#########################################################


