我是Python新手,如果太简单,请提前道歉。找不到任何内容,并且this question没有帮助
我的代码是
# Split data
y = starbucks_smote.iloc[:, -1]
X = starbucks_smote.drop('label', axis = 1)
# Count labels by type
counter = Counter(y)
print(counter)
Counter({0: 9634, 1: 2895})
# Transform the dataset
oversample = SMOTE()
X, y = oversample.fit_resample(X, y)
# Print the oversampled dataset
counter = Counter(y)
print(counter)
Counter({0: 9634, 1: 9634})
如何保存过采样数据集以备将来使用
我试过了
data_res = np.concatenate((X, y), axis = 1)
data_res.to_csv('sample_smote.csv')
出错了
ValueError: all the input arrays must have same number of dimensions,
but the array at index 0 has 2 dimension(s) and the array at index 1 has 1 dimension(s)
谢谢你的建议
您可以创建数据帧:
然后将
data_res
保存到CSV基于连接od} 使维度兼容:
numpy.arrays
的解决方案也是可能的,但需要^{相关问题 更多 >
编程相关推荐