MindsDB enables you to use Machine Learning to ask predictive questions about your data and receive accurate answers from it, all in SQL. With MindsDB:
QuestDB is the fastest open-source, column-oriented SQL database for time-series data. It has been designed and built for massively-parallelized vectorized execution and SIMD, as the de-facto backend for high-performance demanding applications in financial services, IoT, IIoT, ML, MLOps, DevOps and observability. QuestDB implements ANSI SQL with additional extensions for time-specific queries, which make it simple to correlate data from multiple sources using relational and time series joins, and execute aggregation functions with simplicity and speed. In addition, QuestDB is resource efficient (comparatively cheaper than other projects to run in cloud environments), simple to install, manage, use, and stable in all production environments.
Combining both MindsDB and QuestDB gives you unbound prediction ability with SQL. You can perform all the pre-processing of your data inside QuestDB using its powerful and unique extended SQL, and then you can access these data from MindsDB, in its own also unique SQL, to produce powerful ML models.
The main goal of this article is to gently introduce these two deep technologies and give you enough understanding to be able to undertake very ambitious ML projects. To that end we will:
Software repositories in case you are inclined to look under the hood (Give us a star!):
We have this docker-compose.yaml file:
which allows us to start our two service containers with command:
MindsDB takes about 60-90 seconds to become available, logs can be followed in the terminal:
We can stop the two containers with command:
We can remove all persisted data and configuration executing:
Note: Doing this means that the next time you start the containers you will need to add QuestDB as a datasource again, as well as recreate the table, add data, and recreate your ML models.
We can access QuestDB's web console at localhost:9000 :
and execute this DDL query to create a simple table (copy this query to the web console, select it and click Run):
We can upload data from a local CSV file to QuestDB:
More information available here!.
We could equally populate table house_rentals_data with random data (excellent tutorial on this):
Either way, this gives us 100 data points, one every 4 hours, from 2021-01-16T12:00:00.000000Z (QuestDB's timestamps are UTC with microsecond precision), conveniently downloaded to file sample_house_rentals_data.csv.
NOTE: If you tried the last query, you will have 200 rows, you can truncate table house_rentals_data and run the curl command again, in QuestDB data are immutable.
We can connect to MindsDB with a standard mysql-wire-protocol compliant client (no password, hit ENTER):
Only two databases are relevant to us, questdb and mindsdb
To see questdb as a database we need to add it:
This is a read-only view on our QuestDB instance. We can query it leveraging the full power of QuestDB's unique SQL syntax because statements are sent from MindsDB to QuestDB without interpreting them. It only works for SELECT statements (it requires activation by means of USE questdb;):
Beyond SELECT statements, for instance when we need to save the results of a query into a new table, we need to use QuestDB's web console available at localhost:9000:
Contains the metadata tables necessary to create ML models and add new data sources:
We can create a predictor model mindsdb.home_rentals_model_ts to predict the rental_price for a neighborhood considering the past 20 days, and no additional features:
This triggers MindsDB to create/train the model based on the full data available from QuestDB's table house_rentals_data (100 rows) as a timeseries on column ts.
You can see the progress by monitoring the log output of the mindsdb Docker container, and you can ask MindsDB directly:
When status is complete the model is ready for use, until then, we simply wait while we observe MindsDB's logs, and repeat the query periodically. Creating/training a model will take time proportional to the number of features, i.e.cardinality of the source table as defined in the inner SELECT of the CREATE PREDICTOR statement, and the size of the corpus, i.e. number of rows. The model is a table in MindsDB:
We can get more information about the trained model, how was the accuracy calculated or which columns are important for the model by executing the DESCRIBE statement.
Or, to see how the model encoded the data prior to training we can execute:
Additional information about the models and how they can be customized can be found on the Lightwood docs.
The latest rental_price value per neighborhood in table questdb.house_rentals_data (as per the uploaded data) can be obtained directly from QuestDB executing query:
To predict the next value:
In this article, we have introduced QuestDB and MindsDB in a hands-on approach. QuestDB can help you store, analyse, and transform timeseries data, while MindsDB can help you make predictions about it. Albeit simple, our use case should have lowered the entry barrier to these two deep technologies, and now you can deepen your knowledge further by undertaking more ambitious ML projects.
Thank you for getting this far!!!, if you liked this content we'd love to know your thoughts, please come and say hello in our welcoming communities:
See you soon!