Résultat:GridSearchCVK=3alpha code example
Example: Résultat:GridSearchCVK=3alpha
def fit_model_optimize_hyperparams(data, targets, model, params_to_optimize,
cv=None):
"""Optimize estimator hyperparameters.
Perform hyperparamter optimization using
`sklearn.model_selection.GridSearchCV`.
Parameters
----------
data : Pandas.DataFrame
Features for training model.
targets : Pandas.Series
Targets corresponding to feature vectors in `data`.
model : sklearn estimator object
The model/estimator whose hyperparameters are to be optimized.
params_to_optimize : dict or list of dict
Dictionary with parameter names as keys and lists of values to try
as values, or a list of such dictionaries.
cv : int, cross-validation generator or an iterable, optional
Number of folds (defaults to 3) or an iterable yielding train/test
splits. See documentation for `GridSearchCV` for details.
Returns
-------
`sklearn.model_selection.GridSearchCV` estimator object
"""
optimized_model = GridSearchCV(model, params_to_optimize, cv=cv)
optimized_model.fit(data, targets)
return optimized_model