我有一个具有以下维度的数据集,用于训练和测试集-
X_train =(58149,9),y_train =(58149,),X_test =(24921,9)和y_test =(24921,)
我使用LightGBM分类器为RandomizedSearchCV提供的代码如下-
# Parameters to be used for RandomizedSearchCV-
rs_params = {
# 'bagging_fraction': [0.6, 0.66, 0.7],
'bagging_fraction': sp_uniform(0.5, 0.8),
'bagging_frequency': sp_randint(5, 8),
# 'feature_fraction': [0.6, 0.66, 0.7],
'feature_fraction': sp_uniform(0.5, 0.8),
'max_depth': sp_randint(10, 13),
'min_data_in_leaf': sp_randint(90, 120),
'num_leaves': sp_randint(1200, 1550)
}
# Initialize a RandomizedSearchCV object using 5-fold CV-
rs_cv = RandomizedSearchCV(estimator=lgb.LGBMClassifier(), param_distributions=rs_params, cv = 5, n_iter=100)
# Train on training data-
rs_cv.fit(X_train, y_train)
当我执行此代码时,它给我以下错误-
LightGBMError:检查失败:bagging_fraction <= 1.0,位于/__w/1/s/python-package/compile/src/io/config_auto.cpp,第295行。
关于出什么问题了吗?
谢谢!
答案 0 :(得分:0)
我已从您的代码中删除了sp_uniform
和sp _ randint
,并且运行良好
from sklearn.model_selection import RandomizedSearchCV
import lightgbm as lgb
np.random.seed(0)
d1 = np.random.randint(2, size=(100, 9))
d2 = np.random.randint(3, size=(100, 9))
d3 = np.random.randint(4, size=(100, 9))
Y = np.random.randint(7, size=(100,))
X = np.column_stack([d1, d2, d3])
rs_params = {
'bagging_fraction': (0.5, 0.8),
'bagging_frequency': (5, 8),
'feature_fraction': (0.5, 0.8),
'max_depth': (10, 13),
'min_data_in_leaf': (90, 120),
'num_leaves': (1200, 1550)
}
# Initialize a RandomizedSearchCV object using 5-fold CV-
rs_cv = RandomizedSearchCV(estimator=lgb.LGBMClassifier(), param_distributions=rs_params, cv = 5, n_iter=100,verbose=1)
# Train on training data-
rs_cv.fit(X, Y,verbose=1)
并且根据文档 bagging_fraction将为<= 0 || > = 1
添加冗长= 1,以便您可以查看模型的拟合 详细信息会向我们提供您的模型信息。