1
$\begingroup$

I'm using decision tree classification for a classification problem. I have preprocessed the data, train/test split it, and run a model with cross validation before testing it. The steps I followed for preprocessing are outlined below:

  1. Removed some occurences (rows) which aren't usable
  2. Transformed some of the columns by taking nth-root to remove skew (n is different for each column, I plotted the data and did whatever looked like it reduced the skew most)
  3. Train/test split the data
  4. I fit OneHotEncoder() and StandardScaler() to the training data
  5. I applied the transformations in step 4 to both the training and test data

My questons are as follows:

  1. Are my steps correct? In particular, is it correct to 'root transform' the data before train/test split, or does that lead to data leakage?
  2. When I want to apply my model to new data (after testing etc.) does that new data have to undergo identical preprocessing? e.g. fit to the train set then apply it to the new data and root transformations of the same nth-root.

Thanks in advance

$\endgroup$

2 Answers 2

1
$\begingroup$
  1. You are correct, as Evolving_Richie commented.

  2. When you want to apply you model, you have to follow the same process you did when training. However, you only need to transform in the same way, never fit! So the process would be: Remove occurrences/samples (you are accepting that you won't have predictions for these values, if not, change you approximation), transform columns, transform OneHotEncoder() and StandardScaler(). Of course we are not splitting data into training and test because we are on deployment, and all our data is test.

$\endgroup$
1
$\begingroup$

Root transforming your data won't lead to leakage; you're just taking the square root of each number. Data leakage would only occur if your transform meant that the information from data points 'leak' into other datapoints. If I mean centre my data, then each datapoint now contains information about other data in the set (i.e., the mean) so that would be leakage. square root transform on a datapoint requires no info from other datapoints so won't result in leakage.

Standard scaler on the other hand will result in data leakage, so you should do it to train and test separately

As an aside, I don't think a decision tree requires you to address skew in your features.

$\endgroup$
2
  • $\begingroup$ Thanks for that explanation, it was very helpful. Does that mean that for the second question I would just fit and transform to the new data set rather than first fitting to the training set? I feel like data leakage is only important between train and test and once the model has been trained, data leakage doesn't have an effect $\endgroup$
    – Zac Khan
    Aug 18, 2022 at 11:18
  • $\begingroup$ Basically, your plan you outlined in your question is fine, and the order is correct. Do that :) Except you can remove step 2 if you want as it's probably unnecessary. re: your question 2, Yes, if you get new data, you DO need to do identical transforms. $\endgroup$ Aug 18, 2022 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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