Forecast Monthly Expenditures with Nixtla's StatsForecast and MindsDB
In this tutorial, we’ll create a model to forecast expenditures based on historical data using the Nixtla’s StatsForecast engine.
Connect a database
We use a table from our MySQL public demo database, so let’s start by connecting it to MindsDB.
Now that we’ve connected our database to MindsDB, let’s query the data to be used in the example:
Deploy a time-series model
Please note that before using the StatsForecast engine, you should create it with the below command:
You can check the available engines with this command:
Let’s create a model table to forecast the expenditures:
We can check the training status with the following query:
Make 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.
The historical_expenditures
table is used to make batch predictions. Upon joining the quarterly_expenditure_forecaster
model with the historical_expenditures
table, we get predictions for the next quarter as defined by the HORIZON 3
clause.
MindsDB provides the LATEST
keyword that marks the latest training data point. In the WHERE
clause, we specify the month > LATEST
condition to ensure the predictions are made for data after the latest training data point.
If we train the model using data from January 2020 until December 2020 (as defined by WINDOW 12
), then the predictions come for the first quarter of 2021 (as defined by HORIZON 3
).