-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathevaluate_poi_identifier.py
77 lines (36 loc) · 1.32 KB
/
evaluate_poi_identifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# coding: utf-8
# In[1]:
import pickle
import sys
from feature_format import featureFormat, targetFeatureSplit
# In[2]:
data_dict = pickle.load(open("C:/Users/Geekquad/ud120-projects/final_project/final_project_dataset_modified_unix.pkl", "rb"))
# In[3]:
features_list = ['poi', 'salary']
data = featureFormat(data_dict, features_list)
labels, features = targetFeatureSplit(data)
# In[10]:
import sklearn
import numpy as np
from sklearn.cross_validation import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn import svm
# In[6]:
features_train, features_test, labels_train, labels_test = train_test_split(features, labels, test_size = 0.3, random_state=42)
# In[7]:
clf = DecisionTreeClassifier()
clf.fit(features_train, labels_train)
print("Accuracy:", clf.score(features_test, labels_test))
print(clf.predict(features_test))
# In[12]:
print('np.array(labels_test):')
print(np.array(labels_test))
# In[16]:
print('POIs predict:', clf.predict(features_test))
print('Number of POIs predict:', len([e for e in labels_test if e == 1.0]))
# In[17]:
print("Number of tests:", len(labels_test))
# In[21]:
from sklearn.metrics import *
print("precision:", precision_score(labels_test, clf.predict(features_test)))
print("recall:", recall_score(labels_test, clf.predict(features_test)))