from  imblearn.over_sampling  import SMOTE
from  imblearn.over_sampling  import ADASYN
import numpy as np
import pandas as pd

#加载数据
data=pd.read_excel("C:/Users/Administrator/Desktop/论文数据部分/数据/PCA处理/删除重复行 -乱序.xlsx")
data =data.as_matrix()
X=data[:,0:35]
y=data[:,35]


#SMOTE合成
X_resampled_smote, y_resampled_smote = SMOTE().fit_sample(X, y)
print(X_resampled_smote.shape)
print(y_resampled_smote.shape)

y_resampled_smote=y_resampled_smote.reshape(X_resampled_smote.shape[0],1)
c=np.hstack((X_resampled_smote,y_resampled_smote)).astype(float)
print(c.shape)

#保存数组
data_df = pd.DataFrame(c)
writer = pd.ExcelWriter('C:/Users/Administrator/Desktop/data_new_SMOTE.xlsx')
data_df.to_excel(writer) # float_format 控制精度
writer.save()




#ADASYN合成
X_resampled_adasyn, y_resampled_adasyn = ADASYN().fit_sample(X, y)
print(X_resampled_adasyn.shape)
print(y_resampled_adasyn.shape)
y_resampled_adasyn=y_resampled_adasyn.reshape(X_resampled_adasyn.shape[0],1)
d=np.hstack((X_resampled_adasyn,y_resampled_adasyn)).astype(float)
print(d.shape)

#保存数组
data_df = pd.DataFrame(d)
writer = pd.ExcelWriter('C:/Users/Administrator/Desktop/data_new_ADSYN.xlsx')
data_df.to_excel(writer) # float_format 控制精度
writer.save()
