feat_sel = SelectFromModel(LogisticRegression(penalty='l1'))
clf = svm.LinearSVC()
pipe = Pipeline(steps=[('fs',feat_sel), ('clf',clf)])
param = dict(fs__estimator__C=np.logspace(-2, 4, 7),clf__C=np.logspace(-3, 1, 5))
gs = GridSearchCV(pipe, param, cv=5)
gs.fit(X, y)
我正在尝试调整模型的超参数(例如:逻辑回归),然后我用它来选择要素。但是,当选择标准(例如小C)太严格时,有时不会选择任何特征。
UserWarning: No features were selected: either the data is too noisy or the selection test too strict.
有没有办法捕获此错误并使GridSearchCV删除该参数的特定值并继续下一步,而不会导致代码中断?我想这样做,因为我的X动态变化。