方差阈值显示 RuntimeWarning: Degrees of freedom <= 0 for slice
Variance thresholding shows RuntimeWarning: Degrees of freedom <= 0 for slice
我有一个特征数据框,我想删除低方差特征。我使用以下函数过滤掉低方差列:
def variance_threshold_selector(data, threshold):
selector = VarianceThreshold(threshold)
selector.fit(data)
return data[data.columns[selector.get_support(indices=True)]]
对于不同的阈值,我收到以下警告:
/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
这些警告是什么,我该如何解决它们?
关注此 post:
RuntimeWarning: Degrees of freedom <= 0 for slice
当你使用错误的形状时出现
关注此 :
RuntimeWarning: invalid value encountered in less_equal
最有可能发生的原因是 np.nan 某处涉及的输入
然后是 post:
RuntimeWarning: invalid value encountered in greater
您的问题是由 out_vec 数组中的 NaN 或 Inf 元素引起的
我有一个特征数据框,我想删除低方差特征。我使用以下函数过滤掉低方差列:
def variance_threshold_selector(data, threshold):
selector = VarianceThreshold(threshold)
selector.fit(data)
return data[data.columns[selector.get_support(indices=True)]]
对于不同的阈值,我收到以下警告:
/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
这些警告是什么,我该如何解决它们?
关注此 post:
RuntimeWarning: Degrees of freedom <= 0 for slice
当你使用错误的形状时出现
关注此
RuntimeWarning: invalid value encountered in less_equal
最有可能发生的原因是 np.nan 某处涉及的输入
然后是 post:
RuntimeWarning: invalid value encountered in greater
您的问题是由 out_vec 数组中的 NaN 或 Inf 元素引起的