pulse2percept.model_selection
Model selection
|
- class pulse2percept.model_selection.BaseOptimizer(estimator, search_params, **params)[source]
Abstract base class for all optimizers.
Added in version 0.7.
- Parameters:
estimator (
sklearn.base.estimator) – A scikit-learn estimator, such as a classifier or regressor, that containsfitandpredictmethods.serch_params (dict) – Initial values of all search parameters.
has_loss_function ({False | True}) – If True, the estimator’s scoring function is really a loss function (where smaller values indicate better performance) rather than a true scoring function.
verbose ({False | True}) – If True, will print debug information.
- fit(X, y=None, fit_params=None)[source]
Optimizes the values of the search parameters
Runs the optimizer to determine the optimal values of the search parameters. After optimization, two new attributes are available:
best_score: contains the best score achieved with optimal parameter valuesbest_params: a dict containing the optimal parameter values
- Parameters:
X (array-like of shape (n_samples, n_features)) – Sample data.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
fit_params (dict, optional) – Additional parameters that should be passed to the estimator’s
fitmethod.
- predict(X)[source]
Predicts the labels of X
Uses the estimator’s
predictmethod to predict the labels of X.- Parameters:
X (array-like of shape (n_samples, n_features)) – Sample data.
- Returns:
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted labels for X.
- score(X, y, sample_weight=None)[source]
Return the score of the model on the data X
Uses the estimator’s
scoremethod to determine the model score.- Parameters:
X (array-like of shape (n_samples, n_features))
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
- Returns:
score (float)
- property is_fitted
A flag indicating whether the model has been fitted
- class pulse2percept.model_selection.FunctionMinimizer(estimator, search_params, **params)[source]
Loss function minimization
Function minimization using SciPy’s minimize to find the
search_paramsthat optimize anestimator’s score.Added in version 0.7.
- Parameters:
estimator (
sklearn.base.estimator) – A scikit-learn estimator, such as a classifier or regressor, that containsfitandpredictmethods.serch_params (dict of tupels (lower bound, upper bound)) – Dictionary of tupels containing the lower and upper bound of values for each search parameter.
search_params_init (dict of floats, optional) – Initial values of all search parameters. If None, initialize to midpoint between lower and upper bounds
method (str, optional) – Solving method to use (e.g., ‘Nelder-Mead’, ‘Powell’, ‘L-BFGS-B’)
tol (float, optional) – Tolerance for termination. For detailed control, use solver-specific options.
options (dict, optional) – A dictionary of solver-specific options.
has_loss_function ({False | True}) – If True, the estimator’s scoring function is really a loss function (where smaller values indicate better performance) rather than a true scoring function.
verbose ({False | True}) – If True, will print debug information.
- fit(X, y=None, fit_params=None)[source]
Optimizes the values of the search parameters
Runs the optimizer to determine the optimal values of the search parameters. After optimization, two new attributes are available:
best_score: contains the best score achieved with optimal parameter valuesbest_params: a dict containing the optimal parameter values
- Parameters:
X (array-like of shape (n_samples, n_features)) – Sample data.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
fit_params (dict, optional) – Additional parameters that should be passed to the estimator’s
fitmethod.
- property is_fitted
A flag indicating whether the model has been fitted
- predict(X)[source]
Predicts the labels of X
Uses the estimator’s
predictmethod to predict the labels of X.- Parameters:
X (array-like of shape (n_samples, n_features)) – Sample data.
- Returns:
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted labels for X.
- score(X, y, sample_weight=None)[source]
Return the score of the model on the data X
Uses the estimator’s
scoremethod to determine the model score.- Parameters:
X (array-like of shape (n_samples, n_features))
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
- Returns:
score (float)
- class pulse2percept.model_selection.GridSearchOptimizer(estimator, search_params, **params)[source]
Performs a grid search
Exhaustive search over specified parameter values for an estimator.
Added in version 0.7.
- Parameters:
estimator (
sklearn.base.estimator) – A scikit-learn estimator, such as a classifier or regressor, that containsfitandpredictmethods.serch_params (dict) – Dictionary of search parameters with a discrete number of values for each.
has_loss_function ({False | True}) – If True, the estimator’s scoring function is really a loss function (where smaller values indicate better performance) rather than a true scoring function.
verbose ({False | True}) – If True, will print debug information.
- fit(X, y=None, fit_params=None)[source]
Optimizes the values of the search parameters
Runs the optimizer to determine the optimal values of the search parameters. After optimization, two new attributes are available:
best_score: contains the best score achieved with optimal parameter valuesbest_params: a dict containing the optimal parameter values
- Parameters:
X (array-like of shape (n_samples, n_features)) – Sample data.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
fit_params (dict, optional) – Additional parameters that should be passed to the estimator’s
fitmethod.
- property is_fitted
A flag indicating whether the model has been fitted
- predict(X)[source]
Predicts the labels of X
Uses the estimator’s
predictmethod to predict the labels of X.- Parameters:
X (array-like of shape (n_samples, n_features)) – Sample data.
- Returns:
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted labels for X.
- score(X, y, sample_weight=None)[source]
Return the score of the model on the data X
Uses the estimator’s
scoremethod to determine the model score.- Parameters:
X (array-like of shape (n_samples, n_features))
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
- Returns:
score (float)
- exception pulse2percept.model_selection.NotFittedError[source]
Exception class used to raise if optimizer is used before fitting
This class inherits from both ValueError and AttributeError to help with exception handling and backward compatibility.
- add_note()
Exception.add_note(note) – add a note to the exception
- name
attribute name
- obj
object
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class pulse2percept.model_selection.ParticleSwarmOptimizer(estimator, search_params, **params)[source]
Performs particle swarm optimization
Optimizes the search parameter values using a particle swarm.
Added in version 0.7.
- Parameters:
estimator (
sklearn.base.estimator) – A scikit-learn estimator, such as a classifier or regressor, that containsfitandpredictmethods.serch_params (dict of tupels (lower bound, upper bound)) – Dictionary of tupels containing the lower and upper bound of values for each search parameter.
swarm_size (int, optional, default: 10 * number of search params) – The number of particles in the swarm.
max_iter (int, optional, default: 100) – Maximum number of iterations for the swarm to search.
min_func (float, optional, default: 0.01) – The minimum change of swarm’s best objective value before the search terminates.
min_step (float, optional, default: 0.01) – The minimum step size of swarm’s best objective value before the search terminates.
has_loss_function ({False | True}) – If True, the estimator’s scoring function is really a loss function (where smaller values indicate better performance) rather than a true scoring function.
verbose (bool, optional, default: True) – Flag whether to print more stuff
- fit(X, y=None, fit_params=None)[source]
Optimizes the values of the search parameters
Runs the optimizer to determine the optimal values of the search parameters. After optimization, two new attributes are available:
best_score: contains the best score achieved with optimal parameter valuesbest_params: a dict containing the optimal parameter values
- Parameters:
X (array-like of shape (n_samples, n_features)) – Sample data.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
fit_params (dict, optional) – Additional parameters that should be passed to the estimator’s
fitmethod.
- property is_fitted
A flag indicating whether the model has been fitted
- predict(X)[source]
Predicts the labels of X
Uses the estimator’s
predictmethod to predict the labels of X.- Parameters:
X (array-like of shape (n_samples, n_features)) – Sample data.
- Returns:
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted labels for X.
- score(X, y, sample_weight=None)[source]
Return the score of the model on the data X
Uses the estimator’s
scoremethod to determine the model score.- Parameters:
X (array-like of shape (n_samples, n_features))
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
- Returns:
score (float)