Extensions to sklearn¶
Extends sklearn’s GridSearchCV to a model search object
-
class
mriqc.classifier.sklearn_extension.
ModelAndGridSearchCV
(param_grid, scoring=None, fit_params=None, n_jobs=1, iid=True, refit=True, cv=None, verbose=0, pre_dispatch=u'2*n_jobs', error_score=u'raise', return_train_score=True)[source]¶ Bases:
sklearn.model_selection._search.BaseSearchCV
Adds model selection to the GridSearchCV
-
class
mriqc.classifier.sklearn_extension.
ModelParameterGrid
(param_grid)[source]¶ Bases:
future.types.newobject.newobject
Grid of models and parameters with a discrete number of values for each. Can be used to iterate over parameter value combinations with the Python built-in function iter. Read more in the User Guide. Parameters ———- param_grid : dict of string to sequence, or sequence of such
The parameter grid to explore, as a dictionary mapping estimator parameters to sequences of allowed values. An empty dict signifies default parameters. A sequence of dicts signifies a sequence of grids to search, and is useful to avoid exploring parameter combinations that make no sense or have no effect. See the examples below.>>> from mriqc.classifier.model_selection import ModelParameterGrid >>> param_grid = {'model1': [{'a': [1, 2], 'b': [True, False]}], 'model2': [{'a': [0]}]} >>> len(ModelParameterGrid(param_grid)) == 5 True >>> list(ModelParameterGrid(param_grid)) == ( ... [{'a': 1, 'b': True}, {'a': 1, 'b': False}, ... {'a': 2, 'b': True}, {'a': 2, 'b': False}]) True >>> grid = [{'kernel': ['linear']}, {'kernel': ['rbf'], 'gamma': [1, 10]}] >>> list(ModelParameterGrid(param_grid)) == [('model2', {'a': 0}), ... ('model1', {'a': 1, 'b': True}), ... ('model1', {'a': 1, 'b': False}), ... ('model1', {'a': 2, 'b': True}), ... ('model1', {'a': 2, 'b': False})] True >>> ModelParameterGrid(param_grid)[1] == ('model1', {'a': 1, 'b': True}) True
ModelAndGridSearchCV
:- Uses
ModelParameterGrid
to perform a full parallelized parameter search.