DS_Geek
DS_Geek

Reputation: 53

AttributeError: 'DataFrame' object has no attribute 'name' when using SMOTE

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

Upvotes: 2

Views: 3768

Answers (1)

glemaitre
glemaitre

Reputation: 1003

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]

Upvotes: 3

Related Questions