Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. from sklearn.tree import DecisionTreeClassifier
  2. from sklearn.grid_search import GridSearchCV
  3.  
  4. decision_tree_classifier = DecisionTreeClassifier()
  5.  
  6. parameter_grid = {'max_depth': [1, 2, 3, 4, 5],
  7. 'max_features': [1, 2, 3, 4]}
  8.  
  9. cross_validation = StratifiedKFold(all_classes, n_folds=10)
  10.  
  11. grid_search = GridSearchCV(decision_tree_classifier, param_grid = parameter_grid,
  12. cv = cross_validation)
  13.  
  14. grid_search.fit(all_inputs, all_classes)
  15.  
  16. print "Best Score: {}".format(grid_search.best_score_)
  17. print "Best params: {}".format(grid_search.best_params_)
  18.  
  19. Best Score: 0.959731543624
  20. Best params: {'max_features': 2, 'max_depth': 2}
  21.  
  22. Best Score: 0.973154362416
  23. Best params: {'max_features': 3, 'max_depth': 5}
  24.  
  25. Best Score: 0.973154362416
  26. Best params: {'max_features': 2, 'max_depth': 5}
  27.  
  28. Best Score: 0.959731543624
  29. Best params: {'max_features': 3, 'max_depth': 3}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement