AttributeError:使用SMOTE时,“ DataFrame”对象没有属性“名称”

时间:2019-12-23 09:54:15

标签: python-3.x dataframe oversampling imblearn smote

我正在使用imblearn过采样SMOTE技术来平衡我的不平衡数据集。

这是我的示例代码

import pandas as pd
dataset=pd.read_csv('E://IOT_Netlume//hourly_data.csv')
features= dataset.iloc[:,[1,2,3,4]]
target= dataset.iloc[:,[5]]
from imblearn.over_sampling import SMOTE

# applying SMOTE to our data and checking the class counts
resampled, yresampled = SMOTE(random_state=42).fit_resample(features, target)

因此,每当我尝试拟合SMOTE模型时,它就会向我显示属性错误。 AttributeError:“ DataFrame”对象没有属性“ name”。有人可以帮我解决这个问题吗?

我还已经安装了库pip

  

Windows-10-10.0.15063-SP0 Python 3.6.5 | Anaconda,Inc. | (默认为3月   29 2018,13:32:41)[MSC v.1900 64位(AMD64)] NumPy 1.17.4 SciPy   1.3.2 Scikit-Learn 0.22   上面提到的是安装的版本。

功能和目标输出 features output target output

1 个答案:

答案 0 :(得分:1)

不平衡学习0.6将接受X的数据帧和y的序列。但是写的时候

target= dataset.iloc[:,[5]]

target将是一个数据帧(2D),而不平衡学习则需要一个序列(1D)。 只需编辑您的代码即可获得一个系列:

target = dataset.iloc[:, 5]