相同的脚本,相同的数据集,不同的结果

问题描述

我正在构建具有分层kfold交叉验证的XGBClassifier。通过交叉验证对超参数进行调整之后,当脚本在不同的计算机上运行时,我的结果会有很大不同。

在一台计算机上,我得到的验证分数为0.8016。此分数随折叠而变化。

在另一台计算机上,我每次获得的验证分数都恰好是0.5。

我正在为加权ROC-AUC进行优化。代码如下:

models,params_list = list(),list()

outter_skf = StratifiedKFold(n_splits=5,shuffle=True,random_state=RANDOM_STATE)

for train_index,val_index in outter_skf.split(outter_X,outter_y):
    outter_X_tr,outter_X_val = outter_X.iloc[train_index],outter_X.iloc[val_index]
    outter_y_tr,outter_y_val = outter_y.iloc[train_index],outter_y.iloc[val_index]

    estimator = XGBClassifier()

    param_distributions = {
        "scale_pos_weight": [1,10,13,15,20,50,100],"max_depth": range(3,1),"min_child_weight": range(1,6,"n_estimators": [100,200,300,400,500,1000],"learning_rate": [0.001,0.01,0.02,0.05,0.1],"subsample": [i / 10.0 for i in range(8,10)],"gamma": [0,1,5],"random_state": [RANDOM_STATE],"objective": ["binary:logistic"],}

    classes = [0,1]

    weights = compute_class_weight(
        class_weight="balanced",classes=classes,y=outter_y_tr
    )

    c_s = dict(zip(classes,weights))

    sample_weight = pd.DataFrame(compute_sample_weight(class_weight=c_s,y=outter_y_tr),index=outter_y_tr.index.values)

    score_params = {"sample_weight": sample_weight}

    my_scorer = make_scorer(weighted_roc_auc,greater_is_better=True,needs_proba=True,needs_threshold=False,**score_params)

    rscv = RandomizedSearchCV(
        estimator=estimator,param_distributions=param_distributions,n_iter=100,cv=StratifiedKFold(n_splits=10,random_state=RANDOM_STATE),scoring=my_scorer,verbose=1,random_state=RANDOM_STATE,n_jobs=-1,)

    rscv.fit(outter_X_tr,outter_y_tr,sample_weight=sample_weight)

    models.append(rscv.best_estimator_)
    params_list.append(rscv.best_params_)

    rscv_bs = rscv.best_score_
    rscv_vs = roc_auc_score(
        y_true=outter_y_val,y_score=rscv.best_estimator_.predict_proba(outter_X_val)[:,1],sample_weight=compute_sample_weight(class_weight=c_s,y=outter_y_val),)

    print(f"Random Search Best Score : {rscv_bs} | Validation Score : {rscv_vs}")

请帮助:(

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...