我正在使用SMOTE对信用卡数据进行过采样。我使用的是用geeksforgeeks.org (Link)编写的代码
在运行以下代码后,它会声明如下内容:
print("Before OverSampling, counts of label '1': {}".format(sum(y_train == 1)))
print("Before OverSampling, counts of label '0': {} \n".format(sum(y_train == 0)))
# import SMOTE module from imblearn library
# pip install imblearn (if you don't have imblearn in your system)
from imblearn.over_sampling import SMOTE
sm = SMOTE(random_state = 2)
X_train_res, y_train_res = sm.fit_sample(X_train, y_train.ravel())
print('After OverSampling, the shape of train_X: {}'.format(X_train_res.shape))
print('After OverSampling, the shape of train_y: {} \n'.format(y_train_res.shape))
print("After OverSampling, counts of label '1': {}".format(sum(y_train_res == 1)))
print("After OverSampling, counts of label '0': {}".format(sum(y_train_res == 0))) 输出:
Before OverSampling, counts of label '1': 345
Before OverSampling, counts of label '0': 199019
After OverSampling, the shape of train_X: (398038, 29)
After OverSampling, the shape of train_y: (398038,)
After OverSampling, counts of label '1': 199019
After OverSampling, counts of label '0': 199019因为我在这方面完全是个新手。我不明白如何以CSV格式显示这些数据。如果有人能在这个问题上帮助我,我将非常高兴。
或者,如果有任何参考资料,我可以使用SMOTE从数据集中生成合成数据,并将更新后的数据集保存到CSV文件中,请注意。
如下图所示:

提前谢谢。
发布于 2019-11-01 13:57:52
从你的代码中我可以看到,你的X_train_res和其他的都是Python Numpy数组。你可以这样做:
import numpy as np
import pandas as pd
y_train_res = y_train_res.reshape(-1, 1) # reshaping y_train to (398038,1)
data_res = np.concatenate((X_train_res, y_train_res), axis = 1)
data.savetxt('sample_smote.csv', data_res, delimiter=",")无法运行并检查它,但如果您遇到任何问题,请让我知道。
注意:您需要做更多的工作才能向其中添加列标签。让我知道,一旦你通过这个,并需要帮助。
https://stackoverflow.com/questions/58654649
复制相似问题