Skip to content
Open
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
27 changes: 26 additions & 1 deletion evolutionary_search/cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down