Open VinaTsai opened 3 years ago
# 运用SMOTE算法实现训练数据集的平衡
over_samples = SMOTE(random_state=123)
over_samples_X,over_samples_y = over_samples.fit_sample(X_train, y_train)
#over_samples_X, over_samples_y = over_samples.fit_sample(X_train.values,y_train.values.ravel())
# 重抽样前的类别比例
print(y_train.value_counts()/len(y_train))
# 重抽样后的类别比例
print(pd.Series(over_samples_y).value_counts()/len(over_samples_y))
0 0.989017
1 0.010983
Name: y, dtype: float64
1 0.5
0 0.5
dtype: float64
install imblearn
https://imbalanced-learn.readthedocs.io/en/stable/install.html
import