Skip to content

Commit 27561a4

Browse files
authored
Add files via upload
1 parent 12c8d60 commit 27561a4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

K means.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
# coding: utf-8
3+
4+
# In[1]:
5+
6+
7+
import pickle
8+
import numpy
9+
import sys
10+
import matplotlib.pyplot as plt
11+
sys.path.append(".../tools/")
12+
from feature_format import featureFormat, targetFeatureSplit
13+
14+
15+
# In[5]:
16+
17+
18+
def Draw(pred, features, poi, mark_poi=False, name='image.png', f1_name='feature 1', f2='feature 2'):
19+
colors = ["b", "c", "k", "m", "g"]
20+
for ii, pp in enumerate(pred):
21+
plt.scatter(features[ii][0], features[ii][1], color= colors[pred[ii]])
22+
23+
if mark_poi:
24+
for ii, pp in enumerate(pred):
25+
if poi[ii]:
26+
plt.scatter(features[ii][0], features[ii][1], color="r", marker="*")
27+
28+
plt.xlabel(f1_name)
29+
plt.ylabel(f2_name)
30+
plt.savefig(name)
31+
plt.show()
32+
33+
34+
# In[9]:
35+
36+
37+
data_dict = pickle.load(open("C:/Users/Geekquad/final_project_dataset_modified_unix.pkl", "rb"))
38+
data_dict.pop("TOTAL", 0)
39+
40+
41+
# In[10]:
42+
43+
44+
feature_1 = 'salary'
45+
feature_2 = "exercised_stock_options"
46+
poi = "poi"
47+
features_list = [poi, feature_1, feature_2]
48+
data = featureFormat(data_dict, features_list)
49+
poi, finance_features = targetFeatureSplit(data)
50+
51+
52+
# In[11]:
53+
54+
55+
for f1, f2 in finance_features:
56+
plt.scatter(f1, f2)
57+
plt.show()
58+

0 commit comments

Comments
 (0)