Monday, April 17, 2017

Azure Machine Learning: Regression Using Boosted Decision Tree Regression

Today, we're going to continue our walkthrough of Sample 4: Cross Validation for Regression: Auto Imports Dataset.  In the previous posts, we walked through the Initial Data Load, Imputation, Ordinary Least Squares Linear Regression and Online Gradient Descent Linear Regression phases of the experiment.
Experiment So Far
Let's refresh our memory on the data set.
Automobile Price Data (Clean) 1

Automobile Price Data (Clean) 2
We can see that this data set contains a bunch of text and numeric data about each vehicle, as well as its price.  The goal of this experiment is to attempt to predict the price of the car based on these factors.  Specifically, we're going to be walking through the Boosted Decision Tree Regression algorithm.  Let's start by talking about Decision Tree Regression.
Example Decision Tree
For this example, we used our data set to create a single decision tree with 5 leaves (circled in blue).  Basically, a decision tree is built by choosing the "best" split for each node, then repeating this process until the specified number of leaves is reached.  There's a complex process for choosing the "best" threshold that we won't go into detail on.  You can read more about this process here, here and here.

In our example, we start with the entire dataset.  Then, a single threshold is defined for a single variable that defines the "best" split.  Next, the data is split across the two branches.  On the false side, the algorithm decides that there's not enough data to branch again or the branch would not be "good" enough, so it ends in a leaf.  This means that any records with a value of "Engine Size" > 182 will be assigned a "Predicted Price" of $6,888.41.
Example Decision Tree Predictions
We can see that this is the case by looking at the scored output.  Next, the records with "Engine Size" <= 182 will be passed to the next level and the process will repeated until there are exactly 5 leaves.  Later in this post, we'll see where the 5 came from.

Now, we've talked about "Decision Tree Regression", but what's "Boosted Decision Tree Regression"?  The process of "Boosting" involves creating multiple decision trees, where each decision tree depends on those that were created before it.  For example, assume that we want to build 3 boosted decision trees.  The first decision tree would attempt to predict the price for each record.  The next tree would be calculated using the same algorithm, but instead of predicting price, it would try to predict the difference between the actual price and the price predicted by the previous tree.  This is known as a residual because it is what's "left over" after the tree is built..  For example, if the first tree predicted a price of 10k, but the actual price was 12k, then the second tree would be trying to predict 12k - 10k = 2k instead of the original 12k.  This way, when the algorithm is finished, the predicted price can be calculated simply by running the record through all of the trees, and adding all of the predictions.  However, the process for building the individual trees is more complicated than this example would imply.  You can read about it here and here.  Let's take a look at the "Boosted Decision Tree Regression" module in Azure ML.
Boosted Decision Tree Regression
Some of you may notice that these are the same parameters used in the "Two-Class Boosted Decision Tree" module, which we covered in an earlier post.  Because of the similarity, some of the following descriptions have been lifted from that post.

The "Maximum Number of Leaves per Tree" parameter allows us to set the number of times the tree can split.  It's important to note that splits early in the tree are caused by the most significant predictors, while splits later in the tree are less significant.  This means that the more leaves we have (and therefore more splits), the higher our chance of Overfitting is.  We'll talk more about this in a later post.

The "Minimum Number of Samples per Leaf Node" parameters allows us to set the significance level required for a split to occur.  With this value set at 10, the algorithm will only choose to split (this is known as creating a "new rule") if at least 10 rows, or observations, will be affected.  Increasing this value will lead to broad, stable predictions, while decreasing this value will lead to narrow, precise predictions.

The "Learning Rate" parameter allows us to set how much difference we see from tree to tree.  MSDN describes this quite well as "the learning rate determines how fast or slow the learner converges on the optimal solution. If the step size is too big, you might overshoot the optimal solution. If the step size is too small, training takes longer to converge on the best solution."

The "Random Number Seed" parameter allows us to create reproducible results for presentation/demonstration purposes.  Since this algorithm is not random, this parameter has no impact on this module.

Finally, we can choose to deselect "Allow Unknown Categorical Levels".  When we train our model, we do so using a specific data set known as the training set.  This allows the model to predict based on values it has seen before.  For instance, our model has seen "Num of Doors" values of "two" and "four".  So, what happens if we try to use the model to predict the price for a vehicle with a "Num of Doors" value of "three" or "five"?  If we leave this option selected, then this new vehicle will have its "Num of Doors" value thrown into an "Unknown" category.  This would mean that if we had a vehicle with three doors and another vehicle with five doors, they would both be thrown into the same "Num of Doors" category.  To see exactly how this works, check out of our previous post, Regression Using Linear Regression (Ordinary Least Squares).

The options for the "Create Trainer Mode" parameter are "Single Parameter" and "Parameter Range".  When we choose "Parameter Range", we instead supply a list of values for each parameter and the algorithm will build multiple models based on the lists.  These multiple models must then be whittled down to a single model using the "Tune Model Hyperparameters" module.  This can be really useful if we have a list of candidate models and want to be able to compare them quickly.  However, we don't have a list of candidate models.  Strangely, that actually makes "Tune Model Hyperparameters" more useful.  We have no idea what the best set of parameters would be for this data.  So, let's use it to choose our parameters for us.
Tune Model Hyperparameters
Tune Model Hyperparameters (Visualization)
We can see that the "Tune Model Hyperparameters" module will test quite a few different models in order to determine the best combination of parameters.  In this case, it found that a set of 44 trees with 4 leaves, a significance level of 2 records per leaf and a learning rate of .135 has the highest Coefficient of Determination, also known as R Squared.
OLS/OGD Linear Regression and Boosted Decision Tree Regression
Now, our experiment contains 3 different regression methods for predicting the price of a vehicle.  Hopefully, this post opened the door for you to utilize Boosted Decision Tree Regression in your own work.  Stay tuned for our next post where we'll talk about Poisson Regression.  Thanks for reading.  We hope you found this informative.

Brad Llewellyn
Data Scientist

No comments:

Post a Comment