Balancing Interpretability and Predictive Power with Cubist Models in R

Machine learning models are powerful tools that do well in their purpose of prediction. In many business applications, the power of these models is quite beneficial. With any application of a machine learning model, the process to choosing which model involves determining the model that performs best across a given set of criteria. One of these criteria is the interpretability of the model. Neural nets to decision trees, to regression models all have varying levels of interpretability. In many business applications of machine learning, there must be a balance struck between predictive accuracy and interpretability of a model. In this article, we will discuss how Cubist models (in R) are useful in providing effective model interpretability while delivering powerful predictive performance.

[Related Article: Using an Embedding Matrix on Tabular Data in R]

Cubist Background

Cubist models were developed by J.R Quinlan in the paper Learning with Continuous Classes (1992). The cubist model is also referred to as M5. The best description of the cubist model comes from Quinlan’s website and is as follows:

“Cubist is a powerful tool for generating rule-based models that balance the need for accurate prediction against the requirements of intelligibility. Cubist models generally give better results than those produced by simple techniques such as multivariate linear regression, while also being easier to understand than neural networks.”

This description makes clear the balance that cubist models offer between interpretability and predictive power.

Cubist models are a form of decision tree modeling that makes use of rules to subset the data. The primary algorithm contains two steps. The first step establishes a set of rules that divides the data into smaller subsets. The second part of the algorithm that applies a regression model to these smaller subsets to arrive at a prediction.

The predictions can be further augmented through the use of neighbor and committee aspects of the model. The neighbor function will apply a nearest neighbor algorithm to the leaf node and then use an ensemble approach combining the cubist prediction with the nearest neighbor prediction to arrive at a final output. The average prediction that is used in a decision tree is replaced with a regression model at the leaf node. The committee function has a similar benefit to boosting. The first cubist model makes a prediction and subsequent cubist models attempt to adjust for the errors made in the prior models.

Cubist Model in R

To demonstrate a cubist model, we will build a model in R using the rossman store sales data set from We first load our data, remove unwanted features and clean up the date values.

Now with the data prepared we can call the cubist function and generate our model.

We can call our model object to get a high level sense of the framework of the model.

We can see that there are 17 rules that have been found in the data. In other words, there are 17 subsets of the data that each have their own regression model. The model is a very rough model as we did not perform and tuning or take great care in the data preparation stages. We can take a look at slice of the individual models.

Here are the first 3 rules generated by the model and each rules subsequent regression model. Each rule contains the criteria or tree that lead to the regression model. For each rule we can see the specific regression equation used within each rule. An interesting observation here is that rule 1 does not contain a regression model. When the cubist algorithm is evaluating the best models, it is including a model that uses only the median as one of the possible models. If the median performs best then this model is used for the rule.

We can also take a look at an overall evaluation of the model.

We can see the average error which is the normal calculation of MSE. The relative error is ratio of the average error magnitude to the error magnitude that would result from always predicting the mean value. The correlation coefficient is the R-squared measurement. We can also see a breakdown of how the model features influence performance. The Conds column indicates how often the feature was used in a rule criteria and the Model column indicates how often a feature was used in the final model.

[Related Article: Data-Driven Exploration of the R User Community Worldwide]


As we have seen a cubist model does deliver balance between interpretability and predictive power. Cubist models are a great tool to add to a data scientist bag of tricks and can be very useful in business application. The models are relatively easy to follow which can be beneficial when convincing business leaders and users of the value the model can bring to the business.

Original post here.

Read more data science articles on, including tutorials and guides from beginner to advanced levels! Subscribe to our weekly newsletter here and receive the latest news every Thursday.



Our passion is bringing thousands of the best and brightest data scientists together under one roof for an incredible learning and networking experience.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ODSC - Open Data Science

Our passion is bringing thousands of the best and brightest data scientists together under one roof for an incredible learning and networking experience.