title: How to implement ratio-based SMOTE oversampling while CV-ing dataset
body: <p>I'm dealing with a very imbalanced dataset (~5%) on a binary classification problem. I'm piping SMOTE and a Random Forest classifier to get my oversampling happening inside a GridSearch CV loop (as suggested <a href="https://www.marcoaltini.com/blog/dealing-with-imbalanced-data-undersampling-oversampling-and-proper-cross-validation" rel="nofollow noreferrer">here</a>). You can see my implementation below:</p>
  
  <pre><code>from imblearn.over_sampling import SMOTE
  from sklearn.ensemble import RandomForestClassifier
  from imblearn.pipeline import Pipeline
  from sklearn.model_selection import RandomizedSearchCV, StratifiedKFold
  
  sm = SMOTE()
  rf = RandomForestClassifier()
  
  pipeline = Pipeline([('sm', sm), ('rf', rf)])
  
  kf = StratifiedKFold(n_splits = 5)
  
  params = {'rf__max_depth' : list(range(2,5)),
      'rf__max_features' : ['auto','sqrt'],
      'rf__bootstrap' : [True, False]
  }
  
  grid = RandomizedSearchCV(pipeline, param_distributions = params, scoring = 'f1', cv = kf)
  
  grid.fit(X, y)
  </code></pre>
  
  <p>However, <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.477.1151&amp;rep=rep1&amp;type=pdf" rel="nofollow noreferrer">this paper</a> (see Table 4 page 7) suggests testing different resampling ratios to figure out which one gives a better performance. Right now, with my <strong>sm = SMOTE()</strong> I'm generating a 50-50% dataset, but I would like to loop over a list of potential ratios (e.g. 5-95, 10-90, etc.). However, the <strong>ratio</strong> parameter in <a href="http://contrib.scikit-learn.org/imbalanced-learn/stable/generated/imblearn.over_sampling.SMOTE.html" rel="nofollow noreferrer">SMOTE</a> doesn't accept a desired percentage ratio, but a specific integer with the number of samples, which I don't think I can do due to my kfold CV (each fold may potentially have a slightly different sample size). How could this be implemented?</p>