Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.tree import DecisionTreeClassifier
- from sklearn.grid_search import GridSearchCV
- decision_tree_classifier = DecisionTreeClassifier()
- parameter_grid = {'max_depth': [1, 2, 3, 4, 5],
- 'max_features': [1, 2, 3, 4]}
- cross_validation = StratifiedKFold(all_classes, n_folds=10)
- grid_search = GridSearchCV(decision_tree_classifier, param_grid = parameter_grid,
- cv = cross_validation)
- grid_search.fit(all_inputs, all_classes)
- print "Best Score: {}".format(grid_search.best_score_)
- print "Best params: {}".format(grid_search.best_params_)
- Best Score: 0.959731543624
- Best params: {'max_features': 2, 'max_depth': 2}
- Best Score: 0.973154362416
- Best params: {'max_features': 3, 'max_depth': 5}
- Best Score: 0.973154362416
- Best params: {'max_features': 2, 'max_depth': 5}
- Best Score: 0.959731543624
- Best params: {'max_features': 3, 'max_depth': 3}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement