如何从imblearn中的RandomUnderSampler获取样本索引 [英] How to get sample indices from RandomUnderSampler in imblearn
问题描述
有人通过imblearn的RandomUnderSampler进行欠采样后,是否知道如何/如何获得所选样本的索引?以前有一个参数"return_indices = True",现在已为新版本删除了该参数,并假定已将其替换为属性"sample_indices_".但是,如果我尝试使用该属性,它将无法正常工作(请参见下面的代码).我正在使用imblearn 0.6.2.版.
Does anyone know if/how one can get the indices of the selected samples after undersampling with imblearn's RandomUnderSampler? There used to be the argument "return_indices=True" which was now removed for the new version and supposingly was replaced with an attribute "sample_indices_". However, if I try to use that attribute, it doesn't work (see code below). I'm using imblearn version 0.6.2.
russs = RandomUnderSampler(random_state=0,sampling_strategy={6: 600}).fit(X_train_point,y_train_point)
russs.sample_indices_
AttributeError Traceback (most recent call last)
<ipython-input-78-8397ba40f19b> in <module>
1 russs = RandomUnderSampler(random_state=0,sampling_strategy={6: 600}).fit(X_train_point,y_train_point)
----> 2 russs.sample_indices
AttributeError: 'RandomUnderSampler' object has no attribute 'sample_indices'
推荐答案
也面临这一问题.自版本0.4起不推荐使用:return_indices不推荐使用.请使用属性sample_indices _.我恢复到0.5.0,并且能够使用旧的return_indices = True参数.
Also facing this.. Despite the fact that the docs say Deprecated since version 0.4: return_indices is deprecated. Use the attribute sample_indices_ instead. I reverted to 0.5.0 and am able to use the old return_indices=True argument.
pip install imbalanced-learn==0.5.0
这篇关于如何从imblearn中的RandomUnderSampler获取样本索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!