# How to oversample only the training set when using cross validation in sklearn

I have an imbalanced dataset, and using oversampling to make it balanced. I am working on a regression problem. For testing purposes I am applying cross validation on the same dataset for now, using scikit-learn's LassoCV().

However, if I do oversampling before CV, then my model easily overfits since the oversampled items will be distributed over training and testing sets during cross validation. I wonder if there is a way to apply oversampling only on the training set after cross validation makes the split. I prefer to use a scikit-learn method, e.g., cross_val_predict. I wonder if it is possible? Or, do I need to write my own code for this task?

• maybe this should have been asked on Stack Overflow. – josh Aug 23 '17 at 13:59