Created
January 9, 2018 16:44
-
-
Save rajatpaliwal/2ed0c86c0380de01a6207fc3dfb5ed32 to your computer and use it in GitHub Desktop.
ML accuracy quiz.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from class_vis import prettyPicture | |
from prep_terrain_data import makeTerrainData | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import pylab as pl | |
features_train, labels_train, features_test, labels_test = makeTerrainData() | |
########################## DECISION TREE ################################# | |
### your code goes here--now create 2 decision tree classifiers, | |
### one with min_samples_split=2 and one with min_samples_split=50 | |
### compute the accuracies on the testing data and store | |
### the accuracy numbers to acc_min_samples_split_2 and | |
### acc_min_samples_split_50, respectively | |
def classify1(features_train, labels_train): | |
from sklearn import tree | |
X = features_train | |
Y = labels_train | |
clf1 = tree.DecisionTreeClassifier(min_samples_leaf=2) | |
clf1 = clf1.fit(X, Y) | |
return clf1 | |
clf1 = classify1(features_train, labels_train) | |
preds1= clf1.predict(features_test) | |
from sklearn.metrics import accuracy_score | |
acc_min_samples_split_2 = accuracy_score(labels_test, preds1) | |
def classify2(features_train, labels_train): | |
from sklearn import tree | |
X = features_train | |
Y = labels_train | |
clf2 = tree.DecisionTreeClassifier(min_samples_split=50) | |
clf2 = clf2.fit(X, Y) | |
return clf2 | |
clf2 = classify2(features_train, labels_train) | |
preds2= clf2.predict(features_test) | |
from sklearn.metrics import accuracy_score | |
acc_min_samples_split_50 = accuracy_score(labels_test, preds2) | |
def submitAccuracies(): | |
return {"acc_min_samples_split_2":round(acc_min_samples_split_2,3), | |
"acc_min_samples_split_50":round(acc_min_samples_split_50,3)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment