This article describes how to use the Displayr API to create a Regression and save values as a JavaScript variable. In this article, you will learn how to run a regression model from the API, and also how to use QScript to extract data from the regression model and output this as a JavaScript variable.
Requirements
- An Enterprise Displayr license with purchased View hours.
- A Displayr document.
Method
Step 1: Do everything in Getting Started with the Displayr API
Once you have done this, open up the document and it should look like this:
Step 2: Obtain the Document secret
To modify a document using the API we need to know its Document secret. This is found by following these steps:
- Go to the document's settings page (if in the document, click on the cog at the top right of the screen and press Document Settings)
- Expand out the Properties section.
- The document secret is located in the bottom-right corner.
Step 3: Download the regression.zip file
- Click here to download the zip file
- Double-click on it to open it
- Save its contents somewhere on your computer or network
The zip file contains:
- A file called regression.QScript which contains a QScript for running the regression and creating a new variable with the predicted values
- A file called regression.py which contains a Python script for running the QScript
Step 2: Edit and run the regression.py file
- Open the file in a text editor
- On line 20, replace insert-document-secret with the document secret (as described above)
- Save the file
- Run the regression.py script using the process in Step 6 of Getting Started with the Displayr API
- Check out the regression model (it has been added as a new page in your document) and the variable at the top of the list under Data Sets contains the predicted values from the model.
Next
How to Obtain the Document Secret for Use in the Displayr API
How to Import Data via the Displayr API
How to Merge Data Files Using the Displayr API