In the previous article, a brief introduction to the S3 object is made as well as a class that encapsulates the CART analysis by the rpart package is illustrated. Extending an earlier article of comparing the three packages (rpart, caret and mlr), this article compares them using the following 3 S3 objects: rpartExt, rpartExtCrt and rpartExtMlr. Like manageris-aemployee so that it can extends the base class in the previous article, it is roughly conceptualized that the last two classes extend the first. On this setting, performance of both classification and regression tasks are compared in this article.
Before getting started, note that the source of these classes can be found in this gist and, together with the relevant packages, it requires 3 utility functions that can be found here.
Let’s get started.
The data is split for both classification and regression.
The constructors are sourced.
The classification task is fit by each of the packages. Note that the constructors of the subclasses (rpartExtCrt and rpartExtMlr) have an option to fit data using the base class (rpartExt) and it is determined by the argument of fitInd. Once it is set TRUE, the constructor of the base class is executed (or the base class is instantiated), resulting that its outcome (named rpt) is kept as a member of the outcome list. Otherwise a null list is added as a placeholder.
Class and names attributes of each object can be seen below. As the latter two are assumed to extend the first, their class attributes include the class name of the first. Also, as fitInd is set TRUE, the base class is instantiated, which can be checked that the names attributes of rpt.cl and crt.cl$rpt are the same.
The performance of the classfication task is compared and, as seen earlier, the classification tree is not sensitive to cp values.
Then the data is fit as regression. Note that the default fitInd value is FALSE and the base class is not instantiated.
The performance of the regression task is compared below. It is found that, unlike the classification task, the cp plays a more role.
the value (0.0049) at the minimum xerror by the rpart package records the least RMSE (0,74)
the 1-SE rule is also questionable by delivering the highest RMSE (1.96)
the best cp value by the caret and mlr packages is 0 and the resulting RMSE (0.95) is higher
The last is due to the way how the grids are set up in these packages. The tuneLength of the caret package is set to 30 so that the cp increments roughly by 0.01 and the increment is set to be exact in the mlr package. Therefore the grids cannot check the impact of cp values in the third or higher decimal points - if the increment were set to be 0.005 (tuneLength=60), their performance would be similar. However (1) it cannot be anticipated how precisely a grid should be constructed and (2) it can cost too much if the size of a grid is quite high. Therefore another strategy of construcing a grid would be necessary. A quick idea is a sequential fit, which fits with a default grid (eg tuneLenght=20) at first so as to select sub-ranges of cp values and then fits with finer grids in those sub-ranges. It would also be necessary to look into the source of the rpart package to see if it is possible to replicate its method.