Here is my Code for feature selection method in Python:
from sklearn.svm import LinearSVC
from sklearn.datasets import load_iris
iris = load_iris()
X, y = iris.data, iris.target
X.shape
(150, 4)
X_new = LinearSVC(C=0.01, penalty="l1", dual=False).fit_transform(X, y)
X_new.shape
(150, 3)
But after getting new X(dependent variable – X_new), How do i know which variables are removed and which variables are considered in this new updated variable ? (which one removed or which three are present in data.)
Reason of getting this identification is to apply the same filtering on new test data.
Best Answer
There are two things that you can do:
coef_
param and detect which column was ignoredtransform
Small modifications for your example
As you see method
transform
do all job for you. And also fromcoef_
matrix you can see that last column just a zero vector, so you model ignore last column from data