In this tutorial, we introduce Nixtla’s TimeGPT integration which offers the first foundational model for time series forecasting. We’ll go through an example to predict the real estate sales.


MindsDB Setup

One way is to sign up for an account at MindsDB Cloud. It is a convenient option as it doesn’t require any installation procedures. You can find the details here.

Alternatively, visit our docs and follow the instructions to manually set up a local instance of MindsDB via Docker or pip. You can also set up MindsDB on AWS following this instruction set.

Creating an ML Engine

You can check the available engines with this command:


If you see the TimeGPT engine on the list, you are ready to follow the tutorials. If you do not see TimeGPT on the list, you will have to create an instance of the engine first with this command:

CREATE ML_ENGINE timegpt FROM timegpt USING timegpt_api_key = '...'

Notice that the USING clause is optional, but you must pass an API key eventually (either at model creation, engine creation, model usage, or in the mindsdb configuration file). The only exception to this is when using If you want your own token please register here (Submit Interest).


Connecting the Data

In this tutorial, we take our House Sales tutorial and redo it using the StatsForecast engine.

We use a table from our MySQL public demo database, so let’s start by connecting MindsDB to it:

CREATE DATABASE mysql_demo_db_houses
WITH ENGINE = 'mysql',
    "user": "user",
    "password": "MindsDBUser123!",
    "host": "",
    "port": "3306",
    "database": "public"

Now that we’ve connected our database to MindsDB, let’s query the data to be used in the example:

FROM mysql_demo_db.house_sales

Here is the output:

|saledate  |house_price_moving_average|type |bedrooms|
|30/09/2007|441854                    |house|2       |
|31/12/2007|441854                    |house|2       |
|31/03/2008|441854                    |house|2       |

The house_sales table stores quarterly house price moving averages per property.

Creating a Model

Let’s create a model table to predict the house price moving average values:

CREATE MODEL nixtla_timegpt_house_sales_predictor
FROM mysql_demo_db
  (SELECT * FROM house_sales)
PREDICT house_price_moving_average
ORDER BY saledate
GROUP BY bedrooms, type
USING ENGINE = 'timegpt';

The syntax is the same as in the original tutorial. But here, we add the USING clause that specifies the ML engine used to make predictions.

We can check the training status with the following query:

DESCRIBE nixtla_timegpt_house_sales_predictor;

Making Predictions

Once the model status is complete, the behavior is the same as with any other AI table – you can query for batch predictions by joining it with a data table:

SELECT m.saledate AS date, m.house_price_moving_average AS forecast
FROM nixtla_timegpt_house_sales_predictor AS m
JOIN mysql_demo_db.house_sales AS t

Here is the output data:

| date                       | forecast |
| 2019-09-30 00:01:00.000000 | 335449.03125   |
| 2019-09-30 00:02:00.000000 | 335449.03125   |
| 2019-09-30 00:03:00.000000 | 335449.03125   |

What’s Next?

Have fun while trying it out yourself!

If this tutorial was helpful, please give us a GitHub star here.