Let's connect Mindsdb with Mariadb shell Locally and Predict the Mobile Price Range

Let's connect Mindsdb with Mariadb shell Locally and Predict the Mobile Price Range

ยท

5 min read

Hello everyone, in this tutorial I'll be explaining how you can connect MariaDB with the Mindsdb cloud and predict Mobile Price Range inside the database.

Pre-requisites

  • MariaDB client

    You can download it here MariaDB
    Or simply use the command if you are using Linux Ubuntu :

      `sudo apt install mariadb-client`
    
  • Mindsdb Account

    Mindsdb provides 30 days of free trial and you don't need a credit card to sign up, unlike other cloud service providers.

  • Internet connection

    We will be connecting to the Mindsdb cloud with the MariaDB client (locally) so we need the Internet to let the MariaDB client talk with Mindsdb and use its services.

That's it, we need just these 3 things and we are ready to get started with this tutorial.

article12.gif

Connecting MariaDB client with MindsDB's Cloud

  1. After successfully installing the MariaDB client, we need to connect it to the Mindsdb cloud. So that we can use Mindsdb services locally.

    mariadb -h cloud.mindsdb.com --port 3306 -u mindsdb_email -p
    

    Using this command MariaDB client will connect to the Mindsdb cloud using those credentials(email and pass) on port number 3306. ss1.png

    mindsdb_email - Email you used during sign up

  2. After this command and clicking on enter button, you will be asked to enter your mindsdb account password. ss2.png As you enter the password and click enter, you will see that we are connected to the Mindsdb cloud. Yay, our MariaDB client is connected to the Mindsdb cloud successfully.

  3. To again cross-check whether we have connected to the Mindsdb cloud. Run the following SQL query :

    show databases;
    

    image.png We get output as 5 databases. Those 5 databases are in-built and given by Mindsdb to us. And by this output, we are sure that our MariaDB client is connected to the Mindsdb cloud.

Adding Dataset

There are actually 2 ways to add a dataset :

  1. Importing CSV file through Mindsdb Web Editor interface.
  2. Inserting manually using SQL insert statement.

We will use the first option for this tutorial as its makes importing datasets effortless. We will add the dataset using the Mindsdb web editor Interface and then revert back to our MariaDB client.

Note : When you import a dataset using the mindsdb web editor, our dataset is stored in the files database as the table_name you gave to it.

  1. Open Mindsdb Web Editor.
  2. Click on the Add Data button.
  3. Go to the Files section
  4. Click on Import File and drag-drop csv dataset file.
  5. Give a name to the table and click on Save and Continue.

image.png

When we are done, we will find the imported dataset inside the files database with mobile_info as the table name.

image.png Here, we can see our mobile_info dataset is imported.

P.S : Ignore the cars_rating dataset, I had imported it earlier for the Mindsdb tutorial. If haven't read that article. Here's the first article link.

Lets us check whether it's showing the dataset in the MariaDB client. It should give us the same output as above.

image.png

SHOW databases;
USE files;
SHOW tables;

Alright, we got the same output. Now we can go ahead and create a Predictor Model.

Let's Begin with Training the ML model to Predict Mobile Price Range

To train the predictor model in Mindsdb we have the keyword CREATE PREDICTOR. We will use this keyword and services from the Mindsdb cloud inside our MariaDB client locally. It's super easy to Train the ML model to predict data using MindsDB.

Let's check out the query for the same

CREATE PREDICTOR mindsdb.mobile_price_range
FROM files(SELECT * FROM mobile_info)
PREDICT price_range;

Query Explanation :

  1. The first line CREATE PREDICTOR mindsdb.mobile_price_range creates mobile_price_range named table inside database named mindsdb.

  2. Second line FROM files(SELECT * FROM mobile_info) selects the dataset from the mobile_info table which is inside files database.

  3. The third line PREDICT price_range; does some magical task behind the scene. When we use the keyword PREDICT mindsdb runs an ML algorithm and lets us predict data.

image.png

Note : Mindsdb free trial version offers a training model limit of up to 10,000 datasets. If your dataset has over 10k rows and columns it might give you errors while training the ML model.

Check the Status of ML Model Training

The CREATE PREDICTOR query takes time to train our ML model based on dataset size. For me, it took less than a second to Train the ML model to predict Mobile Price range.

When we use the following query to check the status of whether our ML model is trained or not.

SELECT * FROM mindsdb.predictors
WHERE name='mobile_price_range';

image.png

We get output somewhat like this and we get a few details regarding our ML model accuracy, the status of the ML model, and whether it's trained or still under process.

Predicting Mobile Price Range

Now we have a Trained Prediction Model using the mobile_info dataset. Let's check how it will predict Mobile Price Range. To do so we will provide data that is not in our dataset. To predict the data, we have the following query

SELECT price_range,price_range_explain
 FROM mindsdb.mobile_price_range
 WHERE battery_power=1866
 AND four_g=1
 AND dual_sim=1
 AND n_cores=8
 AND touch_screen=1
 AND wifi=1;

image.png

Note : The Price range is denoted in 0,1,2 and 3 format. Where 0 -> low cost, 1 -> medium cost, 2 -> high cost, 3 -> very high cost.

Yay ๐Ÿฅณ! If you read the article completely. I hope you have learned something new and also learned how to successfully predict the mobile price range using Mindsdb and MariaDB.

article13.gif

And If you folks have any queries or questions comment down below I would happy to help!!

If you liked this tutorial and found it helpful definitely give it a ๐Ÿ‘ and follow me on Twitter : twitter.com/_Atharva_08 , Github : github.com/StarTrooper08

And if you loved using Mindsdb give it a โญ on Github. Github : github.com/mindsdb/mindsdb

ย