The Ops Community ⚙️

Arman Chand
Arman Chand

Posted on • Updated on

Predicting Mobile Phone Price using MindsDB Cloud

Image description

Introduction

With MindsDB, we can begin predicting in SQL right now. In order to predict the Target price on the basis of the options, we will fetch our dataset and create a model instantly.

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. From Kaggle, we will use a Mobile Worth Classification dataset.

Then we will log in to MindsDB Cloud, connect it to our data, train a model based on the dataset in our data, and attempt to predict mobile costs.

Importing Data to MindsDB Cloud

We will want a dataset at first that contains Mobile worth on the idea of multiple parameters. you'll be able to transfer a duplicate of the dataset here.

Download the dataset from Kaggle https://www.kaggle.com/datasets/iabhishekofficial/mobile-price-classification

and then merely extract it and save the CSV file for later use.
Now allow us to start with our MindsDB Cloud account to require things additional.

Step 1: Login to your existing MindsDB Cloud account or signup for a brand new one here.

Image description

Step 2: Once you've got signed up or logged in to your MindsDB cloud account, you'll be able to realize the MindsDB Cloud Editor displayed for you.
The top panel is for writing the question, all-time low panel is for displaying the results and therefore the right panel lists out a number of the training hub resources to form things easier for the new users.

Image description

Step 3: Click on Add Data from the highest right and on consequent screen that seems, turn to Files rather than Databases and so click on Import File.

Image description

Step 4: Currently on the Import File dashboard, browse the dataset file from your pc, set a name for the Table and then hit the Save and Continue button. this could simply transfer the dataset file for you and build a Table with the name you provided.

Image description

Step 5: Now the GUI returns back to the Editor screen where you can find two generic queries mentioned to either list the tables or query the data in the table that you just uploaded. Let's run both of these queries and check through the results.

Image description

We are now ready to create a Predictor model using our Mobile_Price table that we just uploaded.

Training a Predictor Model

MindsDB makes it extremely easy to define a Predictor model and train it by using a simple SQL syntax.

Step 1: We will now use the CREATE PREDICTOR syntax to create the Predictor. The syntax will be like this.

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

The query get's executed and return successful in the terminal.

Image description

Step 2: The model should take a little while to get created and trained. We can check the status of the model using the syntax below. If the query returns Complete, then the model is ready to use or else wait if it returns Training status.

Image description

Image description

Describing the Predictor Model

MindsDB provides a DESCRIBE statement that we can use to gain some insights into the Predictor Model. We can find more details about the model in the following three ways.

  • By Features
  • By Model
  • By Model Ensemble

By Features

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

This statement is used to find out the type of encoders used on each column to train the model and the role of each of the columns for the model. A sample output for our model is posted below.

Image description

By Model

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

MindsDB uses multiple models internally to train the data and then select the most optimized one for the model to do the predictions. This statement simply lists out all the candidate models used to train the data along with other details. The model with 1 in its selected column is the one that is the most optimized and accurate.

Image description

By Model Ensemble

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

With the above statement, we can simply query out a JSON object that lists out the multiple attributes used to select the best candidate model to do the predictions.

Image description

Querying the Model

Now that we have a tendency to square measure prepared with our Predictor Model, we will merely execute some straightforward SQL question statements to predict the target price supported by the feature parameters.

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

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

This should return the expected price_range having dual_sim value as 0.

Image description

Let's now try predicting the price_range based on multiple feature parameters.

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

This should return the expected price_range having touch_screen values as 0 and int_memory value as 51;

Image description

Conclusion

It's time to wrap up the tutorial. As part of this tutorial, we created a MindsDB Cloud account, uploaded a dataset to the cloud interface, trained a predictor model with the dataset, and predicted the Mobile price range.

Using MindsDB, you can coach your own predictive models using datasets available on the market online. Don't be afraid to give it a try if you want to make all the predictions you want.

As a final note, please LIKE this page if you learn something new and interesting today and feel free to share your feedback below.

Top comments (0)