I used L1-based feature selection shown here in order to select suitable columns from pandas DataFrame X
.
from sklearn.svm import LinearSVC
from sklearn.datasets import load_iris
from sklearn.feature_selection import SelectFromModel
iris = load_iris()
X, y = iris.data, iris.target
lsvc = LinearSVC(C=0.01, penalty="l1", dual=False).fit(X, y)
model = SelectFromModel(lsvc, prefit=True)
X_new = model.transform(X)
However it is not clear to me how can I get the column names. Since X_new
is numpy
array, I tried this:
X_new.dtype.names
But it returns nothing. So, how can I actually understand which columns have been selected?