42
Forecast Metro Traffic using MindsDB Cloud and MongoDB Atlas
In this tutorial, we will be learning to:
π Connect a MongoDB database to MindsDB.
π Train a model to predict metro traffic.
π Get a prediction from the model given certain input parameters.
π Connect a MongoDB database to MindsDB.
π Train a model to predict metro traffic.
π Get a prediction from the model given certain input parameters.
All of that without writing a single line of code and in less than 15 minutes. Yes, you read that right! π―
We will be using the Metro traffic dataset π that can be downloaded from here. You are also free to use your own dataset and follow along the tutorial.
Finally, No! You are not required to have any background in programming or machine learning. As mentioned before you wont be writing a single line of code!
MindsDB is a predictive platform that makes databases intelligent and machine learning easy to use. It allows data analysts to build and visualize forecasts in BI dashboards without going through the complexity of ML pipelines, all through SQL. It also helps data scientists to streamline MLOps by providing advanced instruments for in-database machine learning and optimize ML workflows through a declarative JSON-AI syntax.
Although only SQL is mentioned, MongoDB is also supported.
The dataset contains information about the: Hourly Interstate 94 Westbound traffic volume for MN DoT ATR station 301, roughly midway between Minneapolis and St Paul, MN. More details can be found here.
The dataset is a
.csv
file that contains 9 columns:holiday
: Categorical US National holidays plus regional holiday, Minnesota State Fairtemp
: Numeric Average temp in kelvin
rain_1h
: Numeric Amount in mm of rain that occurred in the hoursnow_1h
: Numeric Amount in mm of snow that occurred in the hourclouds_all
: Numeric Percentage of cloud coverweather_main
: Categorical Short textual description of the current weatherweather_description
: Categorical Longer textual description of the current weatherdate_time
: DateTime Hour of the data collected in local CST timetraffic_volume
: Numeric Hourly I-94 ATR 301 reported westbound traffic volumePhew! With all of that out of the way, we can finally get started! π
mindsdb
and within it a new database cluster named mindsDB
. Typically, it takes a minute or two to provision a cluster. Once it is done, you should have something like this:



mongodb+srv://<username>:<password>@mindsdb.htuqc.mongodb.net/
We will now use this connection string to connect to our database from MongoDB Compass and load our dataset.

mindsDB
and a collection named data
.

mindsDB
listed. Click on it and you will see that it contains a collection named data
. We will be loading data from the .csv
file into this collection. Open the data
collection by clicking on it.

.csv
file. You will now be able to preview your dataset and also assign the data types as shown below. Then, "import" the dataset and wait for a few seconds for the import to finish.


Enter the required details as shown below. The connection string must be similar to:
mongodb+srv://<username>:<password>@mindsdb.htuqc.mongodb.net/mindsDB
Click on "Connect" and that's it! We have successfully linked our Database to MindsDB.
Next, head over to the Datasets tab and click on "From database".
Enter the details as shown below. In the Find field, we can specify a Mongo query using which MindsDB will include only the results of this query in the data source. By specifying {}
, we are telling MindsDB to include every single document in the data
collection in the data source.
Click on "Create" and now we will see that our data source named "Metro Traffic Dataset" has been added. One can check for the quality and also preview the data source.
We are now ready to train an ML model to predict the traffic_volume
using MindsDB.
traffic_volume
.

traffic_volume
.


Let's say we wanted to know the traffic_volume
for some day and all we know is the following:
{
temp: 300, # temperature of 300 Kelvin
clouds_all: 10, # 10% cloud cover
weather_main: "Clouds",
weather_description: "few clouds",
holiday: "None"
}
We can see that the model predicted with 99% confidence that on such a day, the traffic volume would be 832.
You can play with the inputs and run a few more queries and observe the results.
This tutorial can be extended to perform lots of awesome things. For example, it would be interesting to see the dependence between the weather and the traffic volume. Some interesting questions that can be asked are:
traffic_volume
what is the probability the sky is clear βοΈ? What is the probability that it is raining? π§οΈtraffic_volume
, how certain can we be that the day is a holiday? ποΈtraffic_volume
? π€Apart from these, you can also install MindsDB on your machine and connect with your local databases to get predictions. You can also use a BI tool to visualize these predictions. Apart from SQL and MongoDB, you can explore other data source integrations that MindsDB supports like Oracle and Kafka.
If you have made it this far, thank you for your time and hope you found this useful. If you like the article, like it and share it with others.
Happy Querying! π
42