I want to emphasise (increase the weight) of only a subset of data. Lets say I have old and fresh data, I would like to say that old data has to have more weight and therefore has more influence in the decision than the new data.

In scikit-learn I found only class-weight parameter, but it does not change the weight of the samples, only of all samples within the class.

Is there a way to incorporate this emphasis into the gradient boosted trees in spark or xgboost in python?

There might be a fancier way to create dynamic weights but I would probably start with oversampling the subset and see how that goes. So if you've got classes A, B, and C and want to emphasize C, make a duplicate copy of C and insert that into your training data. In other words, assume you have six records to train on:

  1. A1
  2. A2
  3. B1
  4. B2
  5. C1
  6. C2

add:

  1. C1
  2. C2
  • 1
    You should be very wary of this method as it may introduce biases and skewness into your data - e.g. the distribution of certain variables may change. – bradS May 17 at 8:00

If you have a date variable (or something similar), you can create a weight using this.

If you're using XGBoost, there is an option to specify a weight for each instance when creating the DMatrix - feed your observation weighting in here.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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