【发布时间】:2023-04-07 17:04:01
【问题描述】:
我试图粗略了解几个模型的良好参数,包括带有 RandomizedSearchCV 的 LogisticRegression。由于某些参数组合不兼容,我得到 sklearn FitFailedWarning 即Solver newton-cg supports only 'l2' or 'none' penalties, got l1 penalty。
我想简单地忽略那些特定的警告,我发现这样做的解决方案是使用:
from sklearn.exceptions import FitFailedWarning
from sklearn.utils._testing import ignore_warnings
with ignore_warnings(category=[FitFailedWarning]):
grid.fit(x_train, y_train)
我的问题是,虽然这对于大多数网格模型(knn、决策树等)都可以正常工作,但 LogisticRegression 网格会失败并出现错误:
TypeError: issubclass() arg 2 must be a class or tuple of classes
在不使用 ignore_warnings 的情况下进行匹配时
lr_grid.fit(x_train, y_train)
是否有另一种正确的方法可以使带有 LogisticRegression 的 RandomizedSearchCV 的 FitFailedWarning 静音?
【问题讨论】:
标签: python scikit-learn warnings logistic-regression