我是 Python 新手,如果太简单,请提前致歉。我的代码是# Split datay = starbucks_smote.iloc[:, -1]X = starbucks_smote.drop('label', axis = 1)# Count labels by typecounter = Counter(y)print(counter)Counter({0: 9634, 1: 2895})# Transform the datasetoversample = SMOTE()X, y = oversample.fit_resample(X, y)# Print the oversampled datasetcounter = 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)感谢任何提示!
1 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
您可以创建数据框:
data_res = pd.DataFrame(X) data_res['y'] = y
然后保存data_res
到 CSV。
基于连接 od 的解决方案numpy.arrays
也是可能的,但np.vstack
需要使维度兼容:
data_res = np.concatenate((X, np.vstack(y)), axis = 1) data_res = pd.DataFrame(data_res)
添加回答
举报
0/150
提交
取消