Вот некоторый код для справки -
from skopt import BayesSearchCV
from sklearn.pipeline import Pipeline
from sklearn.neural_network import MLPRegressor
from sklearn.linear_model import RidgeCV, LinearRegression, Lasso, ElasticNet, Ridge
pipeline = Pipeline([('regressor', MLPRegressor())])
search_space = [
{'regressor': [RidgeCV()],
'regressor__normalize': [True, False],
'regressor__fit_intercept': [False]},
{'regressor': [Ridge()],
'regressor__normalize': [True, False],
'regressor__copy_X': [True, False],
'regressor__max_iter': [50000],
'regressor__tol': [1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-10],
'regressor__fit_intercept': [False]},
{'regressor': [LinearRegression()],
'regressor__normalize': [True, False],
'regressor__fit_intercept': [False]},
{'regressor': [Lasso()],
'regressor__normalize': [True, False],
'regressor__copy_X': [True, False],
'regressor__max_iter': [50000],
'regressor__warm_start': [True, False],
'regressor__positive': [True, False],
'regressor__tol': [1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-10],
'regressor__selection': ['cyclic', 'random'],
'regressor__fit_intercept': [False]},
{'regressor': [ElasticNet()],
'regressor__max_iter': [50000],
'regressor__copy_X': [True, False],
'regressor__tol': [1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-10],
'regressor__warm_start': [True, False],
'regressor__positive': [True, False],
'regressor__fit_intercept': [False],
'regressor__l1_ratio': [x/10 for x in range(2, 10)],
'regressor__selection': ['random', 'cyclic'],
'regressor__alpha': [.1, .5, .6, .7, .8, .9, 1],
'regressor__normalize':[True, False]}
]
Теперь, когда я запускаю следующее, все нормально.
gs = GridSearchCV(pipeline, search_space, cv=5, n_jobs=-1, verbose=0)
X.replace(-np.inf, 0, inplace=True)
X.replace(np.nan, 0, inplace=True)
gs.fit(X, y)
Но когда я пытаюсь сделать это с BayesSearchCV, я делаю следующее и получить следующую ошибку.
gs = BayesSearchCV(pipeline, search_space, cv=5, n_jobs=-1, verbose=0)
X.replace(-np.inf, 0, inplace=True)
X.replace(np.nan, 0, inplace=True)
gs.fit(X, y)
TypeError: float() argument must be a string or a number, not 'RidgeCV'
В чем здесь проблема? Я не могу найти решение нигде!