【发布时间】:2020-02-27 11:31:58
【问题描述】:
我正在使用信用卡数据通过 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 文件中,请提及。
类似于下图:
提前致谢。
【问题讨论】:
标签: python machine-learning dataset smote