From c295af7917ef6d6ff26f52c2116d77644a331dfe Mon Sep 17 00:00:00 2001 From: Asad Majeed <80450984+ASAD-BE18@users.noreply.github.com> Date: Tue, 9 May 2023 01:33:31 +0500 Subject: [PATCH] make it work for newer sklearn version --- evolutionary_search/cv.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/evolutionary_search/cv.py b/evolutionary_search/cv.py index 699c506..53475be 100644 --- a/evolutionary_search/cv.py +++ b/evolutionary_search/cv.py @@ -3,16 +3,41 @@ import os import warnings +from collections.abc import Sequence import numpy as np import random from deap import base, creator, tools, algorithms from collections import defaultdict 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 +#This code is obtained from the older version of sklearn +def _check_param_grid(param_grid): + 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 enum(**enums): return type("Enum", (), enums)