【问题标题】:Sklearn RandomizedSearchCV OSError: [Errno 5] Input/output errorSklearn RandomizedSearchCV OSError: [Errno 5] 输入/输出错误
【发布时间】:2019-03-03 20:42:47
【问题描述】:

我正在尝试使用 RandomizedSearch 来确定 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)

这是我得到的完整输出,包括错误: Pastebin Link

任何想法为什么会发生这种情况?该错误表明这是 joblib 的问题,但我使用 RandomForest 分类器执行了相同的 randomSearch 代码并且一切正常。

【问题讨论】:

    标签: python machine-learning scikit-learn


    【解决方案1】:

    我遇到了同样的问题,我发现将 xgboost 文件夹中的现有 xgboost.dll 替换为来自http://www.picnet.com.au/blogs/guido/2016/09/22/xgboost-windows-x64-binaries-for-download/ 的二进制文件之一解决了我的问题。

    【讨论】:

    • 感谢您的回复。同时我已经实现了自己的随机搜索,但下次我会按照你的建议尝试。
    猜你喜欢
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    • 2023-03-15
    • 2019-09-21
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    • 2021-04-10
    相关资源
    最近更新 更多