0

I ran the following Python code to take care of my imbalanced data problem. I used the SMOTE function. I am not sure how I would see and export(as an excel file to my desktop)"resample data set" (1: 860 to 0:860). Because I want to take that excel file and process it using another application.Any help is much appreciated

from imblearn.over_sampling import SMOTE

smote = SMOTE()

x_smote , y_smote = smote.fit_sample(x, y)

print('Original dataset:', Counter(y))

print('Resample dataset:', Counter(y_smote)

Output

Original dataset shape Counter({1: 860, 0: 483})

Resample dataset shape Counter({1: 860, 0: 860})

dataista
  • 3,187
  • 1
  • 16
  • 23
tomsam
  • 49
  • 9
  • This question may be similar. https://stackoverflow.com/questions/58654649/how-to-save-synthetic-dataset-in-csv-file-using-smote – Martlark Apr 01 '21 at 01:20

1 Answers1

2

The variable y and y_smote are dataFrame, so to convert them to .csv use

y.to_csv("file1.csv")
y_smote.to_csv("file2.csv")

Locate the files named file1.csv and file2.csv in your root directory

Qwerty
  • 81
  • 4
  • Edit: Nevermind, I ran it for the x values as well. Thanks, it works, but shouldn't I see the values for the predictors too (with this, I only see the output). I will be using SVM will need the values for the predictors too. – tomsam Apr 01 '21 at 01:32
  • values of the predictors? Can you rephrase – Qwerty Apr 01 '21 at 01:41
  • yes, i have 37 predictors and I am trying to see the value of those predictors after SMOTE. I used x_smote.to_csv("file3.csv") to retrieve them. I hope I did it right – tomsam Apr 01 '21 at 15:17