DEV Community

Cover image for Predicting Mobile Phone Prices with MindsDB
Hridya for Learn Earn & Fun

Posted on

Predicting Mobile Phone Prices with MindsDB

Image description

Introduction

MindsDB is an Open-Source AI Layer for databases, For more details, Checkout this blog to know more

This tutorial will teach you how to train a model to predict mobile worth based on many variables, such as clock_speed, battery_power, dual_sim, etc.. with MindsDB

Importing Data into MindsDB Cloud

In order to import the dataset to MindsDB Cloud, we need to first download it from Kaggle and then upload it simply to MindsDB using the steps mentioned below.

Step 1: Create a MindsDB Cloud Account, If you already haven't done so

Image description

Step 2: Download this Dataset

Image description

Step 3: Go into Add Data -> Files -> Import File
Lastly Add the dataset (After downloading you will get a .zip file, You have to extract it and import the csv inside)

Image description

Step 4: Name the Table

Image description

Step 5: To verify the dataset has successfully imported in:

Run this Query:

SHOW TABLES FROM files;
Enter fullscreen mode Exit fullscreen mode

If you see the dataset, then it's imported successfully!

We have imported our dataset into MindsDB, next up we will be creating a Predictor Model!

Training a Model

Step 1: Creating a Predictor Model

MindsDB provides a syntax which exactly does that!

CREATE PREDICTOR mindsdb.predictor_name       (Your Predictor Name)
FROM database_name                            (Your Database Name)
(SELECT columns FROM table_name LIMIT 10000)  (Your Table Name)
PREDICT target_parameter;                     (Your Target Parameter)
Enter fullscreen mode Exit fullscreen mode

Simply replace the paramaters with the ones you want to use

CREATE PREDICTOR mindsdb.mobileprice_predictor
FROM files 
(SELECT * FROM MobilePrices LIMIT 10000)
PREDICT price_range;
Enter fullscreen mode Exit fullscreen mode

Image description

Step 2: Based on the size of the dataset, it might take some time.

There's 3 stages once you run the command to create the model:

  1. Generating: The model's generating!
  2. Training: Model is getting trained with the dataset
  3. Complete: The model is ready to do predictions

To check the status, this is the query:

SELECT status
FROM mindsdb.predictors
WHERE name='mobileprice_predictor'
Enter fullscreen mode Exit fullscreen mode

Once it returns complete we can start predicting with it!

Image description

Describe the Model

Before we proceed to the final part of predicting mobile phone prices, let us first understand the model that we just trained.

MindsDB provides the following 3 types of descriptions for the model using the DESCRIBE statement.

  1. By Features
  2. By Model
  3. By Model Ensemble

By Features

DESCRIBE mindsdb.predictor_model_name.features;
Enter fullscreen mode Exit fullscreen mode

Image description

This query shows the role of each column for the predictor model along with the type of encoders used on the columns while training.

By Model

DESCRIBE mindsdb.predictor_model_name.model;
Enter fullscreen mode Exit fullscreen mode

Image description

This query shows the list of all the underlying candidate models that were used during training. The one with the best performance (whose value is 1), is selected. You can see the value 1 for the selected one in the selected column while others are set at 0.

By Model Ensemble

DESCRIBE mindsdb.predictor_model_name.ensemble;
Enter fullscreen mode Exit fullscreen mode

Image description

This query gives back a JSON output that contains the different parameters that helped to choose the best candidate model for the Predictor Model.

As we are done understanding our Predictor model, let's move on to predicting values.

Predicting the Target Value

We will start by predicting that only 1 feature parameter is supported by price_range and therefore the query should look like this.

NOTE: While predicting always input multiple feature parameters as the prediction accuracy degrades.

SELECT price_range
FROM mindsdb.mobileprice_predictor
WHERE dual_sim ='0';
Enter fullscreen mode Exit fullscreen mode

Image description

The predicted price range should be 0

SELECT price_range 
FROM mindsdb.mobileprice_predictor
WHERE touch_screen ='0' and int_memory = 51;
Enter fullscreen mode Exit fullscreen mode

Image description

The price range should be 3

Mobilistic! We have now successfully predicted the mobile phone price range with MindsDB

Conclusion

This concludes the tutorial here.

Lastly, before you leave, I would love to know your feedback in the Comments section below and it would be really great if you drop a LIKE on this article.

Top comments (1)

Collapse
 
perryleo profile image
perryleo

Great tutorial! I appreciate the step-by-step guide on importing data into MindsDB Cloud and training a model to predict mobile phone prices like mobilecheck.pk/. The explanations on creating a predictor model and describing the model using MindsDB features are very helpful. The predictive queries at the end make it easy to understand how to use the trained model. Overall, a comprehensive and well-explained tutorial. Thanks! ๐Ÿ‘