I am training a XGBoost model for predicting number of applications and the minimum number of applications in training data is 40 and the maximum number of applications is 2000, while in test set minimum number of applications in training data is 400 and the maximum number of applications is 800. Hence the model is getting confused while predicting the value. Any suggestions on how should I solve this issue?


The assumption in supervised ML is that the test set follows the same distribution as the training set. It's clear from your description that this assumption is not satisfied in your data, so it's not very surprising that things don't work well. Beyond the difference in the range of the dependent variable, if the training and test set have been collected independently it's likely that the distributions of the features also differ.

So how to fix this depends on the goal of the task and in particular why the test set and training set don't follow the same distribution:

  • If the difference is not meaningful, i.e. there is no reason to assume that real production data would be different than the training set, then the experiment should be redone after properly randomizing the split between training and test set.
  • If the difference is meaningful, i.e. the test set is purposefully different from the training set because the production data will also be different, then the setup should be redesigned to account for that. For example there could be a step of semi-supervised learning on the test set, which would adapt the model to the new data distribution while leveraging the information from the training data.

You can try transforming the target using MixMaxScaler so that both train and test set's target is between 0 and 1.

from from xgb import XGBRegressor
from sklearn.compose import TransformedTargetRegressor
from sklearn.metrics import r2_score
from sklearn.preprocessing import MinMaxScaler

regressor = XGBRegressor()

model = TransformedTargetRegressor(regressor= regressor,
                                        transformer = MinMaxScaler()

pred = model.predict(testX)
  • $\begingroup$ Hey it's not working. Thanks for the help though $\endgroup$ – Anubhav Nehru Mar 22 at 15:58

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.