过采样与下采样的实现

一、利用pandas

1、df.sample(n=None, frac=None, replace=False, weights=None, random_state=None, axis=None)

过采样与下采样的实现

二、利用imblearn模块

1、下采样

from imblearn.under_sampling import RandomUnderSampler

ran = RandomUnderSampler(return_indices=True)

x_rs, y_rs, dropped = ran.fit_sample(X, y)

2、上采样

from imblearn.over_sampling import RandomOverSampler

ran=RandomOverSampler()

X_ran,y_ran= ran.fit_resample(X,y)

© 版权声明

相关文章

暂无评论

none
暂无评论...