我正在尝试使用随机搜索来确定SKLearn的MLP和XGBoost的最佳催眠参数。在运行优化时,大约运行 50 次后,发生了 OSError。
我用于使用 XGBoost 进行随机搜索的代码:
from scipy.stats import randint as sp_randint
import xgboost as xgb
from sklearn.model_selection import RandomizedSearchCV
from joblib import dump, load
from sklearn.model_selection import StratifiedShuffleSplit
import numpy as np
import pickle
# Reference f1 eval --> https://stackoverflow.com/questions/51587535/custom-evaluation-function-based-on-f1-for-use-in-xgboost-python-api
from sklearn.metrics import f1_score
import numpy as np
def f1_eval(y_pred, dtrain):
y_true = dtrain.get_label()
err = 1-f1_score(y_true, np.round(y_pred))
print("Score: ", str(1 - err))
return 'f1_err', err
neg_samples = len(y[y['canceled_in_6_mon'] == 0])
pos_samples = len(y[y['canceled_in_6_mon'] == 1])
xgb_model = xgb.XGBClassifier(objective= 'reg:logistic', nthread=1,
scale_pos_weight=neg_samples / pos_samples)
parameters = {
'learning_rate': [0.005, 0.01, 0.05, 0.1, 0.15, 0.25, 0.35], #so called `eta` value
'max_depth': sp_randint(10, 100),
'min_child_weight': sp_randint(1, 8),
'silent': [1],
'gamma': [0, 0.2, 0.5, 0.7, 1],
'subsample': [0.5, 0.7, 1],
'colsample_bytree': [0.5, 0.7, 1],
"n_estimators": sp_randint(20, 100),
"max_features": sp_randint(10, 400),
"min_samples_split": sp_randint(2, 20),
"seed": [42],
"min_samples_leaf": sp_randint(1, 5)
}
ss = StratifiedShuffleSplit(n_splits=3, test_size=0.24, random_state=42)
clf = RandomizedSearchCV(estimator=xgb_model, param_distributions = parameters,cv=ss, verbose=10, n_jobs=4, scoring='f1', n_iter=50)
clf.fit(X=X_train, y=np.ravel(y_train), eval_metric=f1_eval)
这是我得到的完整输出,包括错误:帕斯特宾链接
知道为什么会这样吗?该错误表明这是joblib的问题,但是我使用RandomForest分类器执行了相同的randomizedSearch代码,并且一切正常。
我遇到了同样的问题,我发现用 xgboost 文件夹中的现有 xgboost.dll 替换为 http://www.picnet.com.au/blogs/guido/2016/09/22/xgboost-windows-x64-binaries-for-download/中的一个二进制文件解决了我的问题。