This article describes how to convert a predictive model simulator created in Displayr into a tool that can allocate a predicted category for a range of records. The predictive model simulator is designed to only predict one record at a time using the control selections. However, we can update this setup to apply the predictions to all records in a new data set.
Requirements
- An existing regression or machine learning predictive model. This uses the Gradient Boost example from How to Create a Predictive Model Simulator in Displayr.
- New data to apply the predictive model to.
Please note these steps require a Displayr license.
Method
Set up your new data
Either:
- Create a pasted table:
- In the toolbar, select Table > Paste or Enter Table > Paste or type data.
- Paste or enter the respondent-level responses using the same column names as the predictor variable names from your predictive model.
- Create a raw data table:
- Add your new data set to your document via Data Sources > Plus (+).
- Select the variables that match the ones used as predictors in your predictive model.
- In the toolbar, select Table > Raw Data > Variable(s) and tick Variable Names.
Importantly, the response labels need to match exactly those used in your predictive model, otherwise the prediction will be NA for that record.
The column names need to also match the variable names used in your predictive model. The variable name is found under General > General > Name when you select a variable in the Data Sources tree:
Set up your prediction calculation
In this example, we now have a table called raw.data. To predict the outcome from the model on this new data, we can simplify the code as follows:
1. Select Calculation > Custom Code in the toolbar and click your page.
2. Paste the below into the code window:
DF = raw.data
arguments <- list(model, newdata = DF)
as.vector(do.call(predict, arguments))
Update the names of your new data (DF) table and model above, if necessary.
This will now run the prediction algorithm on all our new data:
3. OPTIONAL: Export the predicted category output from the toolbar via Share > Export Report > Excel.
Next
How to Create a Predictive Model Simulator in Displayr