RAI Train and Predict Design Pattern

✓ Compatible with desktop and web



Usually when you build a predictive model the first step is data quality – removing outliers, getting rid of bad data, etc. – and then we need to train the model. Once we have that trained and validated model, we want to leverage it to predict our response variable for other non-training data. Basically, we want to use what we just built. R has this pipeline built in by convention. Most packages that provide prediction algorithms return an object back that can be applied with predict. This model object can be serialized and unserialized (that’s what they call it in the R world).

Here’s the Design Pattern: you can return a serialized model and then send it to other data functions to use for prediction. It can live in the analysis as a Binary Document Property. You can even save the model to a file or database if you wanted to transfer it to other Spotfire analyses.


  • Train a multivariate model on a training set of data
  • Share trained model inside or outside of the Spotfire analysis
  • Demonstration of Train and Predict Design Pattern
  • Simple, easy to read TERR code which can be modified by the user


This template uses dummy data to demonstrate the design pattern.


  • MVRTERR – Example multivariate regression in TERR that returns a serialized model
  • MVRTERR Apply – Takes data and serialized model to generate a vector of predictions


This template uses an example multivariate regression algorithm (lm.fit) to demonstrate serializing and unserializing model prediction objects.


The power of this simple framework is that now I can easily train on a set of data – for instance performance in 2000-2010 – and then predict on a different set of data – say performance in 2011-2016. Because we can rig this all up to marking and filtering, I can interactively change my training set and prediction sets.

I can also use this methodology to build and apply MULTIPLE competing models. For instance, I could make several trained models – one based on ALL the rows of data, one based on a filtering set, and another based on marking. I could then predict using each model: Predict (all), Predict (filter), Predict (mark). I could use these to understand differences between groups.

Building models is critical for prediction, but also can help understand patterns in the underlying data based on the idiosyncrasies that arise in predicted values. Seeing that Predict (all) returns higher values than Predict (mark) would tell me that I just marked a low performing set of rows – or at least more pessimistic.


A template is an analysis file created in TIBCO Spotfire. The intended use is to replace the data and utilize the configured visualizations and calculations.

  1. Download the template to your personal machine. Login into your own Spotfire server and open the downloaded file.
  2. Review the tables shown on the data load page. These are the tables you'll replace.
  3. Replace the data with another Excel sheet or connect the template directly to your database or platform.
  4. Customize with your own data. You are free to embed and incorporate your template into other projects.
  5. All done!

Spotfire Templates are provided as is and do not require licenses.

Leave a Reply

Your email address will not be published. Required fields are marked *

Download Details

RAI Train and Predict Design Pattern

36 sales


  • Your cart is empty.
Product Details
Release date: June 20, 2016
Last updated: June 20, 2016
Current version: 1.0
Software application type: Spotfire Template
File format: .dxp, .xls
Requirements: TIBCO Spotfire 7.0+

Copyright 2021