无法使用抽象方法_sample实例化抽象类FakeSampler

时间:2019-02-20 07:49:40

标签: machine-learning sampling resampling

标题出现错误。我找到了问题here的答案,但这不适用于我的代码。 有人可以帮忙吗?

# Make an identity sampler
from imblearn.base import BaseSampler

class FakeSampler(BaseSampler):

    _sampling_type = 'bypass'

    def _fit_resample(self, X_pca, y_train):
        return X_pca, y_train


fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(15, 15))
sampler = FakeSampler()
clf = make_pipeline(sampler, LinearSVC())
plot_resampling(X_pca, y_train, sampler, ax1)
ax1.set_title('Original data - y={}'.format(Counter(y_train)))

ax_arr = (ax2, ax3, ax4)
for ax, sampler in zip(ax_arr, (RandomOverSampler(random_state=0),
                                SMOTE(random_state=0),
                                ADASYN(random_state=0))):
    clf = make_pipeline(sampler, LinearSVC())
    clf.fit(X_pca, y_train)
    plot_resampling(X_pca, y_train, sampler, ax)
    ax.set_title('Resampling using {}'.format(sampler.__class__.__name__))
fig.tight_layout()

0 个答案:

没有答案