1 回答

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊
您在此處定義的默認(rèn)求解器有問題:
model = LogisticRegression(class_weight='balanced')
這是從以下錯(cuò)誤消息得出的:
ValueError: Solver lbfgs supports only 'l2' or 'none' penalties, got l1 penalty.
此外,在定義參數(shù)網(wǎng)格之前研究文檔可能會(huì)很有用:
penalty: {'l1', 'l2', 'elasticnet', 'none'}, default='l2' 用于指定懲罰中使用的范數(shù)?!皀ewton-cg”、“sag”和“l(fā)bfgs”求解器僅支持 l2 懲罰?!癳lasticnet”僅受“saga”求解器支持。如果為“none”(liblinear 求解器不支持),則不應(yīng)用正則化。
一旦您使用支持所需網(wǎng)格的不同解算器糾正它,您就可以開始:
## using Logistic regression for class imbalance
model = LogisticRegression(class_weight='balanced', solver='saga')
grid_search_cv = GridSearchCV(estimator = model, param_grid = params,
scoring= 'roc_auc',
cv = folds,
return_train_score=True, verbose = 1)
grid_search_cv.fit(X_train_pt_df, y_train_pt_df)
## reviewing the results
cv_results = pd.DataFrame(grid_search_cv.cv_results_)
另請(qǐng)注意,ConvergenceWarning這可能建議您需要增加默認(rèn)值max_iter、tol或切換到另一個(gè)求解器并重新考慮所需的參數(shù)網(wǎng)格。
添加回答
舉報(bào)