我正在研究泰坦尼克号的数据集。我正在尝试使用LightGBM的LGBMClassifier来确定给定的乘客是否幸存下来。我已经创建了一个填充和处理所有数据的管道,并且正在尝试使用BayesSearchCV来优化我的LightGBM超参数。当我使用BayesSearchCV时,收到以下错误:
"TypeError:‘版本’和‘元组’的实例之间不支持'<‘“
我不知道为什么我会得到这个错误,因为我可以将我创建的管道拟合到数据中,并且它可以与Sklearn的GridSearchCV一起工作,所以我不知道这是BayesSearchCV的问题还是只有我有问题。我已经将我的流水线和运行错误的代码放在下面,并在错误发生的位置做了一个标记。
target = 'survived'
categorical_features = ['sex',
#'ticket',
#'cabin',
'embarked']
numeric_features = ['pclass',
'age',
'sibsp',
'parch',
'fare']
train, test = train_test_split(df,test_size=0.20)
numerical_pipe = Pipeline([('imputer', SimpleImputer(strategy = 'mean'))])
categorical_pipe = Pipeline([('imputer', SimpleImputer(strategy = 'constant', fill_value = 'missing')),
('onehot', OneHotEncoder(handle_unknown = 'ignore'))])
preprocessing = ColumnTransformer(transformers = [
('cat', categorical_pipe, categorical_features),
('num', numerical_pipe, numeric_features)])
lgb_pipe = Pipeline([
('preprocess', preprocessing),
('classifier', LGBMClassifier())])
search_space_lgb = {'num_leaves': Integer(1, 500),
'max_depth': Integer(1, 500)}
bayes_search_lgb = BayesSearchCV(lgb_pipe,
search_space_lgb)
bs_lgb = bayes_search_lgb.fit(train[numeric_features + categorical_features],
train[target]) #ERROR HERE
print(bs_lgb.best_params_)这是错误中的一个额外部分,我认为这对识别错误的确切位置很有用。
rvs(self,n_samples,random_state)中的/Applications/anaconda3/lib/python3.7/site-packages/skopt/space/space.py
762
763 for dim in self.dimensions:
--> 764 if sp_version < (0, 16):
765 columns.append(dim.rvs(n_samples=n_samples))
766 else:发现另一个堆栈溢出,错误与我相同(TypeError inside the scikit-optimize package),但没有一个解决方案对我有效。
发布于 2020-08-17 05:00:58
BayesSearchCV来自skopt库。您不必导入整个库,只需键入以下命令:
从skopt导入BayesSearchCV
此外,您可能希望使用shift+tab来仔细检查参数要求。大多数错误发生在参数级别。如果这解决了问题,请让我知道。
发布于 2020-08-28 03:23:18
我已经解决了修改skopt/space/space.py 763-768行的问题
for dim in self.dimensions:
if sp_version < (0, 16):
columns.append(dim.rvs(n_samples=n_samples))
else:
columns.append(dim.rvs(n_samples=n_samples, random_state=rng))转到
for dim in self.dimensions:
try:
columns.append(dim.rvs(n_samples=n_samples, random_state=rng))
except:
columns.append(dim.rvs(n_samples=n_samples))https://stackoverflow.com/questions/63441743
复制相似问题