Skip to content

Commit

Permalink
Merge pull request udacity#10 from UdacityJeremy/master
Browse files Browse the repository at this point in the history
Add key sort flag in feature format and final project
  • Loading branch information
ShengKungYi committed Feb 12, 2015
2 parents 4614cc3 + 5dec3d4 commit bf72b07
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion final_project/poi_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
my_dataset = data_dict

### Extract features and labels from dataset for local testing
data = featureFormat(my_dataset, features_list)
data = featureFormat(my_dataset, features_list, sort_keys = True)
labels, features = targetFeatureSplit(data)

### Task 4: Try a varity of classifiers
Expand Down
2 changes: 1 addition & 1 deletion final_project/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
RESULTS_FORMAT_STRING = "\tTotal predictions: {:4d}\tTrue positives: {:4d}\tFalse positives: {:4d}\tFalse negatives: {:4d}\tTrue negatives: {:4d}"

def test_classifier(clf, dataset, feature_list, folds = 1000):
data = featureFormat(dataset, feature_list)
data = featureFormat(dataset, feature_list, sort_keys = True)
labels, features = targetFeatureSplit(data)
cv = StratifiedShuffleSplit(labels, folds, random_state = 42)
true_negatives = 0
Expand Down
9 changes: 7 additions & 2 deletions tools/feature_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import numpy as np

def featureFormat( dictionary, features, remove_NaN=True, remove_all_zeroes=True, remove_any_zeroes=False ):
def featureFormat( dictionary, features, remove_NaN=True, remove_all_zeroes=True, remove_any_zeroes=False, sort_keys = False):
""" convert dictionary to numpy array of features
remove_NaN=True will convert "NaN" string to 0.0
remove_all_zeroes=True will omit any data points for which
Expand All @@ -45,7 +45,12 @@ def featureFormat( dictionary, features, remove_NaN=True, remove_all_zeroes=True

return_list = []

for key in sorted(dictionary.keys()):
if sort_keys:
keys = sorted(dictionary.keys())
else:
keys = dictionary.keys()

for key in keys:
tmp_list = []
append = False
for feature in features:
Expand Down

0 comments on commit bf72b07

Please sign in to comment.