Last active
February 2, 2017 12:07
-
-
Save haydarai/e4e8b64791ff452a17dfca175642a96e to your computer and use it in GitHub Desktop.
Searching for best parameters
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
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