4
$\begingroup$

I am using the imblearn package to resample some data before applying other transformation/prediction techniques. Specfically, I am using SMOTE in a slightly unconventional way, as a data augmentation technique to upsample all classes rather than just the minority.

I would like to do a pipeline of SMOTE -> PCA -> SVM on data separated into training and test (most likely K-fold). However, consider the following snippet of code from the imblearn pipeline doccumentation:

pipeline = Pipeline([('smt', smt), ('pca', pca), ('knn', knn)])
X_train, X_test, y_train, y_test = tts(X, y, random_state=42)
pipeline.fit(X_train, y_train) 
y_hat = pipeline.predict(X_test)

In the last line, it seems the test data will be resampled, which doesn't make sense -- only the training data should be resampled using this technique, or you will be testing on artificially generated data. The documentation for pipeline.predict() implies samplers are applied during prediction as well. Is there a way to avoid this, besides simply removing SMOTE from the pipeline?

$\endgroup$
1
$\begingroup$

Checking the code on GitHub, it seems that a 'transform' performing the resampling of data is not applied (cf : 'if hasattr(transform, "fit_sample"'): pass). So, from my understanding only modifications that do not resample the test set will be applied.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.