All writing

What I talk about when I talk about trees

Not love, but trees.

Seed of the trees.

Trees are among the first ideas when people realize that putting the rules by hand onto the machines takes toooo much work (Prolog, anyone ?). Wouldn’t it be nice if we could have the machine infer the rule structure for us, given a bunch of examples?

Variances of the trees and Random Forest

Trees are notoriously known for having high variance. When you have a complex problem with many predictors, they get unwieldy and produce erratic output. People don’t like that, they want their trees to have some shape, i.e. certain properties, they prune the trees. This act of introducing some bias into the tree estimator is to make it behave in a certain desirable way. Later on, we will use this same idea, so keep this in mind.

Also people who love trees learned that if they build a bunch of trees and average them all, then they can reduce the variance of the prediction. This is random forest. Random forest is essentially variance reduction.

Boosted trees

And boosting, as an old master said it, is one of the finest ideas to come out of the field. The idea of boosting has its deep roots (pun!) in Mathematics, stemming (another pun) from the idea of integrals by the ancient masters Newton and Leibniz, where you can sum up some functions over some domains if you slice the domain thin enough. It’s the same idea applied here in boosting. In theory, you can use very thin slice estimators in tandem to model some function with great accuracy. (In practice, you have to deal with real world problems like measurement errors or such leading to noise, then you have to know when to stop, but more on that later).

Boosted trees take the cake nowadays over other kinds of trees. And it makes sense. Modern implementations like xgboost are worth the best money. And the people who created it gave it away for free. If everyone who ever used Xgboost to make a profit or save a dime paid the creators some money, they would be so fucking rich.

Boosting is like summation. We can never be wrong letting computers do sums, or can we? I’ve seen people come in with their trees, tune them upside down and fuck off claiming it could not be done.

How should you tune a boosted tree then ?

First, know the god damn trees. Really learn them. And my best advice for you is to learn from the old masters. Learn from different old masters. Learn from the one who created the algorithm, the one who translated it to code. Drink from the source. You only need to know this once for your whole life. And if you choose a career in this field, sometime along the way you’ll need to fit a tree. This is a must!

Second: Know what’s available to tune and how to tune it. This depends on the implementation. for XGboost and contemporary boosted trees, go look at this. https://sites.google.com/view/lauraepp/parameters. This is your navigation map.

Third: Apply your theories. Usually, set your Learning rate first. Smaller the better, but slower. You pick your balance. Then the next most important thing is the depth of the individual trees. Too shallow and it’s slow. Too deep and your trees are complex and have high variance. Remember it’s a bias reduction technique. Big complicated trees will get too much in the details of the learning function. Then it overshoots and the subsequent trees have to correct for it. This is why you have negative values from xgboost when all your targets are non-negative. One tree cannot extrapolate beyond the range it sees. It’s the trees correcting each other.

Do not do the things below. These are sins, may you burn in hell if you do this:

  • Tune the god damn random seed. I have seen this many times. This is for Kaggle fuckwads and crooks. Please god wash my eyes with your holy water.
  • Random search the whole parameter set, especially important things like learning rate and depth of the trees. Technically speaking, doing this will find you a combination of parameters that could produce dangerous results. Like a bunch of very deep trees (high variance and over-correcting each other) that just happen to minimize your CV. Who needs you when all you do is random search on the very thing you’re supposed to provide value on? You will corrupt your own purpose.
  • Listen to fuckwads like me. Remember, it’s better to learn from first-hand knowledge.

What should you do then ? This is hard, as it will depend on your problem at hand. Use the scientific method, start with a theory and validate your theory with your testing schemes. Random search is ok. But remember it’s a very very dangerous tool to use. One day your model will break and by random searching the param set, you do not know what causes it. This is a matter of having principles. This is the science in data science. Know how to ride your bike, and know how to fix it.

bike

Next up:

  • Coding up some trees
  • Imbalances and methods that use subsampling
  • MARS algorithms and fit it with trees and lr