3
$\begingroup$

I have X numpy array as my features and y numpy array as my target. I split both of it into train and test data. From many QnA i have read they only say to preprocess both train and test separately. I assume i only do it to my feature (X) train and test data and not the target (y). Do we also preprocess the target?

$\endgroup$
2
$\begingroup$

Not necessarily but depends on what your target(y) is and which algorithm/methodology you are trying to use. It also depends on your data quality.

Few instances that come to my mind:

  1. If your target value is categorical and multilabel in nature, it needs to be one hot encoded, also think about adding extra category to account for unknown classes

  2. If your target is a continuous variable some transformations could work better depending on data distribution and quality- log transforms are common(if no negatives are present),

  3. Normalization/MinMax scaling etc are employed when different features and targets are in very different scales.

https://machinelearningmastery.com/how-to-transform-target-variables-for-regression-with-scikit-learn/

$\endgroup$
3
$\begingroup$

Do we also preprocess the target?

Sometimes. The most common example is scaling the target variable for regression, which is beneficial for some algorithms. Another example is when the distribution of the target variable is skewed and is processed into being normally distributed by log-transformation.

$\endgroup$
2
  • $\begingroup$ thank you for answering, since you said sometimes, is there any rule of thumb when to do it or not besides of your examples? $\endgroup$ – random student Mar 15 '20 at 6:48
  • $\begingroup$ I would say that it comes with understanding the chosen algorithm. Linear regression works with the assumption that the errors are going to be normally distributed. Then preprocessing the target into being normally distributed makes sense. Gradient descent converges faster with values around 0-1, then scaling the target makes sense. $\endgroup$ – Simon Larsson Mar 15 '20 at 7:24

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.