Predicting Mobile Phone Price using MindsDB Cloud
Published: 2022-10-09 07:14:10


![Image description](https://community.ops.io/remoteimages/uploads/articles/zr1r5d56y6ebn2t9tru3.png)

## 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](https://community.ops.io/remoteimages/uploads/articles/rw31k30hwipf5qo1tv8d.png)

**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](https://community.ops.io/remoteimages/uploads/articles/kyqcme3pbtuwb142zl43.png)

**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](https://community.ops.io/remoteimages/uploads/articles/h6488yctbpwuca2yb9r8.png)

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](https://community.ops.io/remoteimages/uploads/articles/ji3tp27gmr2mwngh7mp2.png)

**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](https://community.ops.io/remoteimages/uploads/articles/qmlabnxe7ebjticfbg99.png)

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.

``` sql
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)
```

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


![Image description](https://community.ops.io/remoteimages/uploads/articles/t9xyc9d0jvxpwtk5aluc.png)

**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](https://community.ops.io/remoteimages/uploads/articles/8xh2txqrdls3lm1polzi.png)


![Image description](https://community.ops.io/remoteimages/uploads/articles/t1jimnkp2hi87jirecmz.png)

## 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

``` sql
DESCRIBE mindsdb.predictor_model_name.features;
```

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](https://community.ops.io/remoteimages/uploads/articles/9nxpqrr12m1sa3p1svnm.png)


## By Model

``` sql
DESCRIBE mindsdb.predictor_model_name.model;
```

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](https://community.ops.io/remoteimages/uploads/articles/9gx63lmk7gqjawl4tqlx.png)

## By Model Ensemble

``` sql
DESCRIBE mindsdb.predictor_model_name.ensemble;
```

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](https://community.ops.io/remoteimages/uploads/articles/etjp61lvx5hx8v89pfaj.png)

## 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.


``` sql
SELECT price_range
FROM mindsdb.Mobile_Price_Predict
WHERE dual_sim ='0';
```

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


![Image description](https://community.ops.io/remoteimages/uploads/articles/6to0bb8humcnjmcm0g1q.png)

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

``` sql
SELECT price_range 
FROM mindsdb.Mobile_Price_Predict
WHERE touch_screen ='0' and int_memory = 51;
```

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


![Image description](https://community.ops.io/remoteimages/uploads/articles/arl2rxjskv7ow5ddhlp0.png)

## 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.