1 回答

TA貢獻1871條經驗 獲得超8個贊
您在此處定義的默認求解器有問題:
model = LogisticRegression(class_weight='balanced')
這是從以下錯誤消息得出的:
ValueError: Solver lbfgs supports only 'l2' or 'none' penalties, got l1 penalty.
此外,在定義參數網格之前研究文檔可能會很有用:
penalty: {'l1', 'l2', 'elasticnet', 'none'}, default='l2' 用于指定懲罰中使用的范數?!皀ewton-cg”、“sag”和“lbfgs”求解器僅支持 l2 懲罰?!癳lasticnet”僅受“saga”求解器支持。如果為“none”(liblinear 求解器不支持),則不應用正則化。
一旦您使用支持所需網格的不同解算器糾正它,您就可以開始:
## 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_)
另請注意,ConvergenceWarning這可能建議您需要增加默認值max_iter、tol或切換到另一個求解器并重新考慮所需的參數網格。
添加回答
舉報