#!/usr/bin/python


"""
    starter code for the validation mini-project
    the first step toward building your POI identifier!

    start by loading/formatting the data

    after that, it's not our code anymore--it's yours!
"""

import pickle
import sys
sys.path.append("../tools/")
from feature_format import featureFormat, targetFeatureSplit

data_dict = pickle.load(open("../final_project/final_project_dataset.pkl", "r") )

### add more features to features_list!
features_list = ["poi", "salary"]

data = featureFormat(data_dict, features_list)
labels, features = targetFeatureSplit(data)

from sklearn import tree
clf = tree.DecisionTreeClassifier() #create decision tree
clf = clf.fit(features, labels)
print clf.score(features, labels)


from sklearn.cross_validation import train_test_split
features_train, features_test, labels_train, labels_test = train_test_split(features, labels, test_size = .3, random_state =42)



clf = tree.DecisionTreeClassifier() #create decision tree classifier again
clf = clf.fit(features_train, labels_train)
pred = clf.predict(features_test)


count = 0
for x, y in enumerate(pred):
    if y==1 and labels_test[x]==1:
        count+=1

print count

from sklearn.metrics import precision_score
from sklearn.metrics import recall_score

print precision_score(labels_test, pred) #test the recall and the precision 
print recall_score(labels_test, pred)


predictions = [0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1] 
true_labels = [0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0]
print precision_score(true_labels, predictions) #test the recall and the precision 
print recall_score(true_labels, predictions)

### it's all yours from here forward!  


