【问题标题】:AttributeError: 'DataFrame' object has no attribute 'name' when using SMOTEAttributeError: 'DataFrame' 对象在使用 SMOTE 时没有属性 'name'
【发布时间】:2020-04-14 14:52:02
【问题描述】:

我正在使用 imblearn over_sampling 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' object has no attribute 'name' 。有人可以帮我解决这个问题吗?

我还安装了 pip 库

Windows-10-10.0.15063-SP0 Python 3.6.5 |Anaconda, Inc.| (默认,三月 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

【问题讨论】:

  • 能否请您打印特征和目标并显示其输出?
  • @Lakshmi-Intel 我已经编辑了我的帖子,请查看并帮助我。

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


【解决方案1】:

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

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

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

target = dataset.iloc[:, 5]

【讨论】:

猜你喜欢
  • 2021-05-27
  • 2020-10-07
  • 2022-07-13
  • 1970-01-01
  • 2013-10-23
  • 2017-04-15
  • 2022-09-28
  • 2017-01-24
  • 2018-10-10
相关资源
最近更新 更多