Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does xgboost handle instance weights #144

Closed
BlindApe opened this issue Jan 18, 2015 · 10 comments
Closed

How does xgboost handle instance weights #144

BlindApe opened this issue Jan 18, 2015 · 10 comments

Comments

@BlindApe
Copy link

Hi,

I think case weights should be present in calcGain and calcWeight functions in any way (multiplying to the grad and hess).
Where are used the case weights?

@tqchen
Copy link
Member

tqchen commented Jan 18, 2015

This is a good question:) The instance weights are blended into gradient and second order gradients. Think about how will you calculate the g and h when you have weighted loss functions.

@BlindApe
Copy link
Author

Think in case weights as repeated cases, so

calcGain = Sqr(case_weight * sum_grad) / (case_weight * sum_hess + reg_lambda);
calcWeight = - case_weight * sum_grad / (case_weight * sum_hess + reg_lambda);

See the R gbm implementation (point 4.3, terminal node estimates):

https://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/inst/doc/gbm.pdf?revision=18&root=gbm&pathrev=22

@tqchen
Copy link
Member

tqchen commented Jan 18, 2015

In xgboost, when you feed things into booster, for each instance i

grad_xgb[i] = grad[i] * case_weight[i]
hess_xgb[i] = hess[i] * case_weight[i]

grad_xgb, and hess_xgb is the statistics you feed into tree constructor. In another word, case_weight is "blended" into the gradient statistics already

@tqchen
Copy link
Member

tqchen commented Jan 18, 2015

In your simplified case, sum_grad *case_weight is the actual sum_grad the calcGain function will see

@tqchen
Copy link
Member

tqchen commented Jan 18, 2015

Interestingly, this question is also covered in this slide http://homes.cs.washington.edu/~tqchen/pdf/BoostedTree.pdf

See the last few slide about questions on weigthted training

@BlindApe
Copy link
Author

I've searched in code and didn't found the weights in grad and hessian. I'll take a second look.

@tqchen
Copy link
Member

tqchen commented Jan 19, 2015

@tqchen tqchen changed the title case weights How xgboost handle instance weights Jan 19, 2015
@tqchen tqchen changed the title How xgboost handle instance weights How does xgboost handle instance weights Jan 19, 2015
@BlindApe
Copy link
Author

Thank you. Seems OK and your terminal node estimates are congruent with given in R gbm document I posted yesterday.
'j = i % nstep' line I suppose is for multinomial loss where there are k preds for each label, ok?

A last thing:
sum_hess in weighted instances is computed in same way? How does this affect the min_child_weight restriction? If all instances have big weights this restriction should be manually incresed or this sum_hess is computed without the weights?

@tqchen
Copy link
Member

tqchen commented Jan 19, 2015

sum_hess is also computed with the weights.

@tqchen tqchen closed this as completed Jan 25, 2015
@vatsan
Copy link
Contributor

vatsan commented Dec 15, 2016

@tqchen
For a user supplied objective, should we manually blend the weights with the gradients & hessian? Sorry i am not able to verify this myself as the link you pointed to doesn't work anymore: (https://github.com/tqchen/xgboost/blob/master/src/learner/objective-inl.hpp#L149).

@lock lock bot locked as resolved and limited conversation to collaborators Oct 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants