2
$\begingroup$

I am trying the variance threshold method for the first time and I am following the example in sklearn to work on it.

>>> X = [[0, 2, 0, 3], [0, 1, 4, 3], [0, 1, 1, 3]]
>>> selector = VarianceThreshold()
>>> selector.fit_transform(X)
array([[2, 0],
       [1, 4],
       [1, 1]])

However, at the end, it only returns an array of the values of the selected features. How can I get the name of the features that met the variance threshold limit here? I just need the names of the selected features.

$\endgroup$
2
$\begingroup$

Use selector.get_support (Documentation). This will give you a mask of the features that were selected and features that were discarded.

>>> selector.get_support()
array([False,  True,  True, False])

And here is how you get your selected features indices

>>> [ i for i, f in enumerate(selector.get_support()) if f ]
[1, 2]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.