小编Mr.*_*oom的帖子

调整阈值cros_val_score sklearn

有没有办法设置sklearn的cross_val_score阈值?

我训练了一个模型,然后将阈值调整为 0.22。型号如下:

# Try with Threshold
pred_proba = LGBM_Model.predict_proba(X_test)


# Adjust threshold for predictions proba
prediction_with_threshold = []
for item in pred_proba[:,0]:
    if item > 0.22 :
        prediction_with_threshold.append(0)
    else:
        prediction_with_threshold.append(1)

print(classification_report(y_test,prediction_with_threshold))
Run Code Online (Sandbox Code Playgroud)

然后我想使用 cross_val_score 验证这个模型。我已经搜索过,但找不到设置 cross_val_score 阈值的方法。我使用的 cross_val_score 如下所示:

F1Scores = cross_val_score(LGBMClassifier(random_state=101,learning_rate=0.01,max_depth=-1,min_data_in_leaf=60,num_iterations=200,num_leaves=70),X,y,cv=5,scoring='f1')
F1Scores

### how to adjust threshold to 0.22 ??
Run Code Online (Sandbox Code Playgroud)

或者还有其他方法使用阈值验证该模型?

python machine-learning scikit-learn cross-validation

7
推荐指数
1
解决办法
2018
查看次数