title: Imbalanced classification: order of oversampling vs. scaling features?
body: <p>When performing classification (for example, logistic regression) with an imbalanced dataset (e.g., fraud detection), is it best to scale/zscore/standardize the features before over-sampling the minority class, or to balance the classes before scaling features? </p>
  
  <p>Secondly, does the order of these steps affect how features will eventually be interpreted (when using <em>all</em> data, scaled+balanced, to train a final model)?</p>
  
  <p>Here's an example:</p>
  
  <p><strong>Scale first:</strong></p>
  
  <ol>
  <li>Split data into train/test folds</li>
  <li>Calculate mean/std using all training (imbalanced) data; scale the training data using these calculations</li>
  <li>Oversample minority class in the training data (e.g, using SMOTE)</li>
  <li>Fit logistic regression model to training data</li>
  <li>Use mean/std calculations to scale the test data</li>
  <li>Predict class with imbalanced test data; assess acc/recall/precision/auc</li>
  </ol>
  
  <p><strong>Oversample first</strong></p>
  
  <ol>
  <li>Split data into train/test folds</li>
  <li>Oversample minority class in the training data (e.g, using SMOTE)</li>
  <li>Calculate mean/std using balanced training data; scale the training data using these calculations</li>
  <li>Fit logistic regression model to training data</li>
  <li>Use mean/std calculations to scale the test data</li>
  <li>Predict class with imbalanced test data; assess acc/recall/precision/auc</li>
  </ol>