Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #79 (not compatible with scikit learn 1.1) #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion evolutionary_search/cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import random
from deap import base, creator, tools, algorithms
from collections import defaultdict
from collections.abc import Sequence
from sklearn.base import clone, is_classifier
from sklearn.model_selection._validation import _fit_and_score
from sklearn.model_selection._search import BaseSearchCV, check_cv, _check_param_grid
from sklearn.model_selection._search import BaseSearchCV, check_cv
from sklearn.metrics import check_scoring
from sklearn.utils.validation import _num_samples, indexable

Expand All @@ -21,6 +22,35 @@ def enum(**enums):
param_types = enum(Categorical=1, Numerical=2)


def _check_param_grid(param_grid):
"""
Validates the parameter grid.
This function used to be available on scikit-learn (versions 1.0 and below)
within the model_selection._search module
"""
if hasattr(param_grid, "items"):
param_grid = [param_grid]

for p in param_grid:
for name, v in p.items():
if isinstance(v, np.ndarray) and v.ndim > 1:
raise ValueError("Parameter array should be one-dimensional.")

if isinstance(v, str) or not isinstance(v, (np.ndarray, Sequence)):
raise ValueError(
"Parameter grid for parameter ({0}) needs to"
" be a list or numpy array, but got ({1})."
" Single values need to be wrapped in a list"
" with one element.".format(name, type(v))
)

if len(v) == 0:
raise ValueError(
"Parameter values for parameter ({0}) need "
"to be a non-empty sequence.".format(name)
)


def _get_param_types_maxint(params):
"""
Returns characteristics of parameters
Expand Down
2 changes: 1 addition & 1 deletion evolutionary_search/optimize.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
import numpy as np
from deap import base, creator, tools, algorithms
from sklearn.model_selection._search import _check_param_grid
from .cv import (
_get_param_types_maxint,
_initIndividual,
_cxIndividual,
_mutIndividual,
_individual_to_params,
_check_param_grid
)
import warnings
import os
Expand Down