# How does imblearn apply the transformations during prediction?

Let's say I have a sklearn pipeline that:

1. Imputes the data
2. Randomly oversamples the minority class
from imblearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from imblearn.over_sampling import RandomOverSampler

pipeline = Pipeline(
[('1', SimpleImputer(strategy='median'),
('2', RandomOverSampler(random_state=0)),
('estimator', <Some Logistic Regression>)
]
)


I can then fit this to my training set pipeline.fit(X_train, y_train) and the random oversampler should properly identify the class to sample. What if I try to predict i.e pipeline.predict(X_test)? Since there are no classes, does the random oversampler still apply? I would expect the imputer to apply regardless but what about RandomOverSampler?

Thank you

• Could you clarify the question please? What do you mean by "since there are no classes"? May 25, 2020 at 20:10
• So when I do pipeline.fit(X_train, y_train), I am providing the classes so RandomOverSampler knows which class is the minority and resamples the data appropriately. When I predict, pipeline.predict() I am not (cannot) providing the classes so RandomOverSampler has no way of telling which is the minority class. May 25, 2020 at 20:14
• okay. 1.I would assume it works like any other fit method where it keeps the learned statistics from train and then apply on the test.2. Even if it doesn't, i would not want to to know the classes in test data and perform good despite the class imbalance problem since in training i specifically made it learn this? May 25, 2020 at 20:28