# Predictive model improvements

> This is content from just-tim, the data-and-analytics channel by Tim Ngwena (formerly 'Tableau Tim'). Tim has 12+ years of hands-on BI experience and covers Tableau most of all, plus Power BI, Looker, Hex, SQL and data modelling, the analytics industry, and the craft of doing the job — always tool-agnostic and honest about the trade-offs.

- **Author:** Tim Ngwena (just-tim, https://just-tim.com/about)
- **Published:** 2020-12-17
- **Format:** Video · 13 min watch · transcript available
- **Topics:** Analytics, AI & ML, Data visualisation
- **Tools:** Tableau (calculated fields, desktop, model quantile, predictive modelling)
- **Canonical:** https://just-tim.com/posts/predictive-model-improvements
- **Watch:** https://www.youtu.be/mYsQW5-O2k4

I walk through the predictive modelling functions in Tableau 2020.4, building a simple Superstore line chart and adding MODEL_QUANTILE to draw a median prediction line. I then show how to switch between the default linear regression, the new regularised linear model and the gaussian process model directly inside a calculation.

## Key takeaways

- MODEL_QUANTILE and MODEL_PERCENTILE let you run predictive analysis in a Tableau calculated field, with linear regression as the default model
- Use a quantile of 0.5 to predict the median, so roughly half the values fall above and half below the line
- Fix the 'cannot mix aggregate and non-aggregate arguments' error by wrapping the date predictor in ATTR() so everything is aggregated
- Specify a model explicitly with the model = '...' syntax, using 'rl' for regularised linear regression and 'gp' for the gaussian process model
- Tableau's documentation gives clear guidance on when to pick each model, and these calculations are far simpler to set up than the equivalent in R

## Chapters

- 0:35 Building a simple line chart
- 1:11 Writing a MODEL_QUANTILE calculation
- 3:10 Fixing aggregation with ATTR
- 4:13 Dual axis and the default model
- 6:01 Switching to explicit model syntax
- 8:46 Regularised linear and gaussian models
- 10:54 Choosing a model and final thoughts

Watch the full video, read the transcript and use chapter deep-links on the page: https://just-tim.com/posts/predictive-model-improvements

---
just-tim — Data and analytics, with a point of view. · https://www.youtube.com/channel/UC7HYxRWmaNlJux-X7rNLZyw · https://twitter.com/TableauTim · https://www.linkedin.com/in/timngwena
