2

I am using imblearn over_sampling SMOTE technique in order to balance my imbalanced dataset.

Here is my sample code

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)

so when ever i try to fit SMOTE model it shows me attribute error. AttributeError: 'DataFrame' object has no attribute 'name' .Can anyone help me regarding this issue?

Also i have pip installed the library

Windows-10-10.0.15063-SP0 Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] NumPy 1.17.4 SciPy 1.3.2 Scikit-Learn 0.22 Above mentioned are the version installed.

features and target output features output target output

DS_Geek
  • 53
  • 1
  • 10

1 Answers1

3

Imbalanced-learn 0.6 will accepts dataframe for X and series for y. However when writing

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

target will be a dataframe (2D) while imbalanced-learn expects a series (1D). Just edit your code to get a series:

target = dataset.iloc[:, 5]
glemaitre
  • 963
  • 6
  • 7
  • We are probably going to be more explicit regarding the error message in the future. The reference issue is available there: https://github.com/scikit-learn-contrib/imbalanced-learn/issues/666 – glemaitre Dec 23 '19 at 14:02