def classify(features_train, labels_train):

    ### your code goes here--should return a trained decision tree classifer
    from sklearn import tree
    clf = tree.DecisionTreeClassifier()
    clf.fit(features_train, labels_train)



    return clf
from sklearn import tree
clf = tree.DecisionTreeClassifier()
clf.fit(features_train, labels_train)
pred = clf.predict(features_test)
from sklearn.metrics import accuracy_score
acc = accuracy_score(pred, labels_test)
### you fill this in!
### be sure to compute the accuracy on the test set



def submitAccuracies():
  return {"acc":round(acc,3)}
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
from sklearn import tree
clf1 = tree.DecisionTreeClassifier(min_samples_split=2)
clf1.fit(features_train, labels_train)
pred1 = clf1.predict(features_test)
clf2 = tree.DecisionTreeClassifier(min_samples_split=50)
clf2.fit(features_train, labels_train)
pred2 = clf2.predict(features_test)
from sklearn.metrics import accuracy_score
acc_min_samples_split_2 = accuracy_score(pred1,labels_test)
acc_min_samples_split_50 = accuracy_score(pred2, labels_test)






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)}


 Here's your output:
{'acc_min_samples_split_50': 0.912, 'acc_min_samples_split_2': 0.908}

results matching ""

    No results matching ""