Machine Learning With SQL
Before any model training and predictions can be done, MindsDB, Deepnote, and your database instance must be connected together properly. This is explained in the following steps.
1. Connect to MindsDB Cloud
The first step is to go to MindsDB Cloud and set up a free account. Once you have an account at MindsDB Cloud, you can connect to your database from within Deepnote (shown below).
2. Create a MindsDB integration in Deepnote
The second step is set up a MindsDB integration from within Deepnote as described here in our docs. You must use mindsdb for the name of the database.
3. Connect to the Database
MindsDB enables connections to your favorite databases, data warehouses, data lakes, using the CREATE DATASOURCE SQL statement.
ℹ️ In this template I will use a pre-created datasource called demo. If you want to try with your own database, add your database credentials to the query below.
Preview the airline satisfaction data
Even though Deepnote is not directly using a postgres integration in this template, it is still connected to the postgres instance via the MindsDB integration. Therefore, you can use SQL cells to look at the raw data as you would normally. Note the use of demo to point to the data. The last column, satisfaction, contains the labels we are trying to predict.
Train a new model
The query below will train a new model called satisfaction_model from demo. Every column from the airline table will be used to predict of satisfaction.
⚠️ Note, if you are running the query more than once, you need to change the model name. Also, to speed up the training time I have used 1000 rows from the data.
Check the training status
To check the training model's status, you can select from the predictors table as shown in the following cell.
⚠️ Training runs in the background. Please wait for the status column to say "complete" before continuing.
Describe trained model
To get more information about the attributes of the trained model, you can use the DESCRIBE model statement. To get more information about how the model encoded the data, prior to training, use DESCRIBE model.features.
Predict customer satisfaction
Finally, to return a prediction, select from the model and provide the parameters for the prediction in the WHERE clause. Let's try predicting satisfaction for a 47-year-old male who flew Business Class.
As you can see, a customer meeting that description is likely to be neutral or dissatisfied according to our model.
In summary
MindsDB allows data teams to leverage SQL for machine learning, truly democratizing data science. Show MindsDB some 💙 by giving their GitHub repo a ⭐.