Skip to content

Instantly share code, notes, and snippets.

@haydarai
Last active February 2, 2017 12:07
Show Gist options
  • Save haydarai/e4e8b64791ff452a17dfca175642a96e to your computer and use it in GitHub Desktop.
Save haydarai/e4e8b64791ff452a17dfca175642a96e to your computer and use it in GitHub Desktop.
Searching for best parameters
from sklearn.grid_search import GridSearchCV
dtc = DecisionTreeClassifier()
parameter_grid = {'criterion': ['gini', 'entropy'],
'splitter': ['best', 'random'],
'max_depth': [1, 2, 3, 4, 5],
'max_features': [1, 2, 3, 4]}
cross_validation = StratifiedKFold(all_classes, n_folds=10)
grid_search = GridSearchCV(dct, param_grid=parameter_grid, cv=cross_validation)
grid_search.fit(all_inputs, all_classes)
print('Best score: {}'.format(grid_search.best_score_))
print('Best parameters: {}'.format(grid_search.best_params_))
dtc = grid_search.best_estimator_
dtc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment