0

I have a dataframe of features and I'd like to remove low variance features. I used the following function to filter out low variance columns:

def variance_threshold_selector(data, threshold):

    selector = VarianceThreshold(threshold)
    selector.fit(data)

return data[data.columns[selector.get_support(indices=True)]]

And I got the following warning for different threshold values:

/anaconda3/envs/Observation/lib/python3.7/site-packages/sklearn/feature_selection/_variance_threshold.py:77: RuntimeWarning: Degrees of freedom <= 0 for slice.
  self.variances_ = np.nanvar(X, axis=0)

/anaconda3/envs/Observation/lib/python3.7/site-packages/sklearn/feature_selection/_variance_threshold.py:88: RuntimeWarning: invalid value encountered in less_equal
  (self.variances_ <= self.threshold)):

/anaconda3/envs/Observation/lib/python3.7/site-packages/sklearn/feature_selection/_variance_threshold.py:99: RuntimeWarning: invalid value encountered in greater

What are these warnings and how can I resolve them?

YNR
  • 867
  • 2
  • 13
  • 28

1 Answers1

0

following this post:

RuntimeWarning: Degrees of freedom <= 0 for slice

occurs when you use the wrong shape

following this post:

RuntimeWarning: invalid value encountered in less_equal

hat's most likely happening because of a np.nan somewhere in the inputs involved

and following this post:

RuntimeWarning: invalid value encountered in greater

Your problem is caused by the NaN or Inf elements in your out_vec array

PV8
  • 5,799
  • 7
  • 43
  • 87