<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 
Step1:  
Step2:  
Step3:  Initial Results
GaussianNB()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accuracy
<ASSISTANT_TASK:>
Python Code:
### Task 1: Select what features you'll use.
### features_list is a list of strings, each of which is a feature name.
### The first feature must be "poi".
names = np.array(my_dataset.keys())
print names.shape, names[:5], "\n"
features_list = my_dataset.itervalues().next().keys()
features_list.sort()
features_list.remove('poi')
features_list.insert(0, 'poi')
features_list.remove('email_address')
print features_list
### convert dictionary to pandas dataframe
df = pd.DataFrame([entry for entry in my_dataset.itervalues()])
df = df.drop('email_address', axis=1)
df = df[features_list]
#df.dtypes
#df.describe()
#df.count()
df.poi = df.poi.astype('int')
df = df.convert_objects(convert_numeric=True)
for col in list(df.columns):
    df[col] = df[col].round(decimals=3)
    
print "POI Count:\n", df.poi.value_counts()
df.head()
# create labels
y = df.poi.values
print y.shape
print y[:5]
# create initial features
X = df.drop('poi', axis=1).values
print X.shape
# imputation for 'NaN' values
imp = Imputer(missing_values='NaN', strategy='mean', axis=0)
imp.fit(X)
X = imp.transform(X)
print X[:5]
### Task 2: Remove outliers
num_rows = X.shape[0]
num_cols = X.shape[1]
rows_to_remove = set()
for i in xrange(num_cols):
    point_five_percentile = np.percentile(X[:,i], 0.5)
    ninety_nine_point_five_percentile = np.percentile(X[:,i], 99.5)
    
    for j in xrange(num_rows):
        if X[j,i] < point_five_percentile:
            #print "\tlow outlier: ", "row: ", j, "col: ", i, " -> ", X[j,i]
            rows_to_remove.add(j)
        elif X[j,i] > ninety_nine_point_five_percentile:
            #print "\thigh outlier: ", "row: ", j, "col: ", i, " -> ", X[j,i]
            rows_to_remove.add(j)
X = np.delete(X, list(rows_to_remove), axis=0)
y = np.delete(y, list(rows_to_remove))
print "names associated with outlier-containing rows to remove:"
for i in rows_to_remove:
    print "\t",names[i]
    
names = np.delete(names, list(rows_to_remove))
print "\nnew X shape: ", X.shape
print "\ntotal rows removed: ", len(rows_to_remove), "({})".format(round(len(rows_to_remove)/float(num_rows), 2))
# split into training and testing data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.20, random_state=42)
print X_train.shape, X_test.shape, y_train.shape, y_test.shape
Explanation: 
End of explanation
### Task 3: Create new feature(s)
# scale
scaler = MinMaxScaler()
scaler = scaler.fit(X_train)
X_train = scaler.transform(X_train)
print X_train.shape
X_test = scaler.transform(X_test)
print X_test.shape
X_train
Explanation: 
End of explanation
### Task 4: Try a varity of classifiers
### Please name your classifier clf for easy export below.
### Note that if you want to do PCA or other multi-stage operations,
### you'll need to use Pipelines. For more info:
### http://scikit-learn.org/stable/modules/pipeline.html
classifiers = dict()
def grid_searcher(clf):
    
    # PUT IN FUNCTION FOR MINMAXSCALER
    
    t0 = time()
    
    even_range = range(2,X.shape[1],2)
    random_state = [42]
    t_or_f = [True, False]
    #powers_of_ten = [10**x for x in range(-5,5)]
    logspace = np.logspace(-5, 5, 10)
    #kernels = ['linear', 'poly', 'rbf', 'sigmoid']  # takes too long, unfortunately
    kernels = ['rbf']
    criteria = ['gini', 'entropy']
    splitters = ['best', 'random']
    max_features = ['auto', 'sqrt', 'log2', None]
    inits = ['k-means++', 'random']
    
    # pca and select K best
    pipeline = make_pipeline(RandomizedPCA(), SelectKBest(), clf)
    
    params = dict(randomizedpca__n_components = even_range,
                  randomizedpca__whiten = t_or_f,
                  randomizedpca__random_state = random_state,
                  selectkbest__k = ['all'])
    
        
    if pipeline.steps[2][0] == 'decisiontreeclassifier':
        params['decisiontreeclassifier__criterion'] = criteria
        params['decisiontreeclassifier__splitter'] = splitters
        params['decisiontreeclassifier__max_features'] = max_features
        params['decisiontreeclassifier__random_state'] = random_state
    
    if pipeline.steps[2][0] == 'svc':
        params['svc__C'] = logspace
        params['svc__kernel'] = kernels
        #params['svc__degree'] = [1,2,3,4,5]  # for use with 'poly'
        params['svc__gamma'] = logspace
        params['svc__random_state'] = random_state
    if pipeline.steps[2][0] == 'kmeans':
        params['kmeans__n_clusters'] = [2]
        params['kmeans__init'] = inits
        params['kmeans__random_state'] = random_state
    
    grid_search = GridSearchCV(pipeline, param_grid=params, n_jobs=4)
    grid_search = grid_search.fit(X_train, y_train)
    print "*"*15, pipeline.steps[2][0].upper(), "*"*15
    #print "\nbest estimator: ", grid_search.best_estimator_, "\n" 
    print "\nBEST SCORE: ", grid_search.best_score_, "\n"
    #print "\nbest params: ", grid_search.best_params_, "\n"
    #print "#"*50
    print "\nBEST ESTIMATOR:"
    clf = grid_search.best_estimator_.fit(X_train, y_train)
    
    #classifiers[pipeline.steps[2][0]] = clf
    
    X_test_pca = clf.steps[0][1].transform(X_test)
    X_test_skb = clf.steps[1][1].transform(X_test_pca) 
    print "new X_test shape: ", X_test_skb.shape
    
    #print "#"*50
    print "\nPREDICTIONS:"
    #test_classifier(clf, my_dataset, features_list)
    print "\nground truth:\n", y_test 
    
    y_pred = clf.steps[2][1].predict(X_test_skb)
    print "\npredictions:\n", y_pred
    #print "#"*50
    print "\nEVALUATIONS:"
    print "\nconfusion matrix:\n", confusion_matrix(y_test, y_pred)
    
    print "\nclassification report:\n", classification_report(y_test, y_pred, target_names=["non-poi", "poi"])
    
    print "ELAPSED TIME: ", round(time()-t0,3), "s"
Explanation: 
End of explanation
grid_searcher(GaussianNB())
grid_searcher(DecisionTreeClassifier())
grid_searcher(SVC())
grid_searcher(KMeans())
Explanation: Initial Results
GaussianNB()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accuracy: 0.25560&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Precision: 0.18481&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Recall: 0.79800&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;F1: 0.30011&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;F2: 0.47968
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Total predictions: 10000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True positives: 1596&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;False positives: 7040&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;False negatives:  404
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;True negatives:  960
New Results
End of explanation
<END_TASK>