You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BaseGroupLasso is implemented as a scikit-learn transformer. As an intermediate step inside a pipeline it works well, but in combination with SelectFromModel (to further remove infinitesimal coefs), it throws an error:
>>>importsklearn, group_lasso>>>sklearn.__version__, group_lasso.__version__
('1.0.2', '1.5.0')
>>>fromgroup_lassoimportGroupLasso>>>fromsklearn.datasetsimportmake_regression>>>fromsklearn.feature_selectionimportSelectFromModel>>>fromsklearn.linear_modelimportRidge>>>fromsklearn.pipelineimportmake_pipeline>>>X, y=make_regression(n_features=5, n_informative=3, random_state=0)
>>>pipe=make_pipeline(SelectFromModel(GroupLasso(supress_warning=True)), Ridge())
>>>pipe.fit(X, y)
---------------------------------------------------------------------------ValueErrorTraceback (mostrecentcalllast)
[<ipython-input-3-e63339588fc2>](https://localhost:8080/#) in <module>()34X, y=make_regression(n_features=5, n_informative=3, random_state=0)
---->5pipe.fit(X, y)
6frames
[/usr/local/lib/python3.7/dist-packages/sklearn/feature_selection/_base.py](https://localhost:8080/#) in _transform(self, X)101returnnp.empty(0).reshape((X.shape[0], 0))
102iflen(mask) !=X.shape[1]:
-->103raiseValueError("X has a different shape than during fitting.")
104returnX[:, safe_mask(X, mask)]
105ValueError: Xhasadifferentshapethanduringfitting.
Possible solutions:
Add a new parameter min_coef and zero out all the coefficients s.t. np.abs(coef_) < min_coef. Optionally, reimplement TransformerMixin methods by inheriting from SelectorMixin to support get_support() and get_feature_names_out() methods.
or
Remove fit_transform and transform methods to enable SelectFromModel(Grouplasso(), threshold=min_coef) inside a pipeline.
The text was updated successfully, but these errors were encountered:
BaseGroupLasso
is implemented as a scikit-learn transformer. As an intermediate step inside a pipeline it works well, but in combination withSelectFromModel
(to further remove infinitesimal coefs), it throws an error:Possible solutions:
min_coef
and zero out all the coefficients s.t.np.abs(coef_) < min_coef
. Optionally, reimplementTransformerMixin
methods by inheriting fromSelectorMixin
to supportget_support()
andget_feature_names_out()
methods.or
fit_transform
andtransform
methods to enableSelectFromModel(Grouplasso(), threshold=min_coef)
inside a pipeline.The text was updated successfully, but these errors were encountered: