Closed Mamba413 closed 1 year ago
@Mamba413 Thanks for you suggestion! I have read the corresponding document. SelectFromModel
selects features throuth a specific attribute (e.g. coef_
), which measures the importance of features, of a base estimator (e.g. abess.LinearRegression
). Therefore, abess
is already compatible with SelectFromModel
and a typical usage can be made as follows:
import numpy as np
from abess.datasets import make_glm_data
from abess import LinearRegression
from sklearn.feature_selection import SelectFromModel
np.random.seed(0)
n, p, k = 300, 1000, 5
data = make_glm_data(n=n, p=p, k=k, family='gaussian')
X, y = data.x, data.y
print(X.shape) # (300, 1000)
model = LinearRegression().fit(X, y)
sfm = SelectFromModel(model, prefit=True)
X_new = sfm.transform(X)
print(X_new.shape) # (300, 5)
@chenpnn Thx! It would be better to mark it on: https://abess.readthedocs.io/en/latest/auto_gallery/5-scikit-learn-connection/plot_1_scikit_learn.html#sphx-glr-auto-gallery-5-scikit-learn-connection-plot-1-scikit-learn-py.
You can feel free to reorganize this Tutorial page.
@chenpnn Thx! It would be better to mark it on: https://abess.readthedocs.io/en/latest/auto_gallery/5-scikit-learn-connection/plot_1_scikit_learn.html#sphx-glr-auto-gallery-5-scikit-learn-connection-plot-1-scikit-learn-py. You can feel free to reorganize this Tutorial page.
Ok, I have added an example to this tutorial page.
Thanks for your contribution! It will be better to use a pull request in future.
Make the estimators in
abess
(likeLinearRegression
andLogisticRegression
) can be used viaSelectFromModel
. See details aboutsklearn.feature_selection.SelectFromModel
in https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SelectFromModel.html#sklearn.feature_selection.SelectFromModel.