データをオーバーサンプリングするために不均衡学習を使用しています。オーバーサンプリング法を使用した後、各クラスにいくつのエントリがあるかを知りたいです。このコードはうまく機能します:
import imblearn.over_sampling import SMOTE
from collections import Counter
def oversample(x_values, y_values):
oversampler = SMOTE(random_state=42, n_jobs=-1)
x_oversampled, y_oversampled = oversampler.fit_resample(x_values, y_values)
print("Oversampling training set from {0} to {1} using {2}".format(dict(Counter(y_values)), dict(Counter(y_over_sampled)), oversampling_method))
return x_oversampled, y_oversampled
しかし、パイプラインの使用に切り替えたので、GridSearchCV を使用して (ADASYN、SMOTE、および BorderlineSMOTE から) 最適なオーバーサンプリング方法を見つけることができます。したがって、実際に fit_resample を自分で呼び出して、次のようなものを使用して出力を失うことはありません。
from imblearn.pipeline import Pipeline
from sklearn.preprocessing import MinMaxScaler
from sklearn.ensemble import RandomForestClassifier
pipe = Pipeline([('scaler', MinMaxScaler()), ('sampler', SMOTE(random_state=42, n_jobs=-1)), ('estimator', RandomForestClassifier())])
pipe.fit(x_values, y_values)
アップサンプリングは機能しますが、トレーニング セットに含まれる各クラスのエントリ数に関する出力が失われます。
パイプラインを使用して最初の例と同様の出力を得る方法はありますか?