Feature Engineering in MindsDB
The more data you have, the more accurate predictions you get.
We recommend you provide the predictor with as many historical data rows and data columns as possible to make your predictions even more accurate. The examples presented here prove this hypothesis.
If you want to follow the examples, please sign up for the MindsDB Cloud account here.
Prerequisites
The base table is available in the example_db
integration in the MindsDB Cloud Editor. In order to be able to use it, you must first create a database like this:
On execution, we get:
Once that’s done, you can run the following commands with us.
Example: Adding More Data Columns
Introduction
Here, we’ll create several predictors using the same table, increasing the number of data columns with each step.
We start with the base table and create a predictor based on it. Then we add two columns to our base table and again create a predictor based on the enhanced table. At last, we add another two columns and create a predictor.
By comparing the accuracies of the predictors, we’ll find that more data results in more accurate predictions.
Let’s get started.
Let’s Run the Codes
Here, we go through the codes for the base table and enhanced base tables simultaneously.
Data Setup
Let’s prepare and verify the data. Here, we create the views and query them to ensure the input for the predictors is in order.
Let’s start by querying the data from the example_db.demo_data.used_car_price
table, which is our base table.
On execution, we get:
Where:
Name | Description |
---|---|
model | Model of the car. |
year | Year of production. |
price | Price of the car. |
transmission | Transmission (Manual , or Automatic , or Semi-Auto ). |
mileage | Mileage of the car. |
fueltype | Fuel type of the car. |
tax | Tax. |
mpg | Miles per gallon. |
enginesize | Engine size of the car. |
Dropping a View If you want to drop a view, run the command DROP VIEW view_name;
.
Creating Predictors
Now, we create predictors based on the example_db.demo_data.used_car_price
table and its extensions.
On execution, we get:
Dropping a Predictor If you want to drop a predictor, run the command DROP MODEL predictor_name;
.
Predictor Status
Finally, let’s check the predictor status whose value is generating
at first, then training
, and at last, complete
.
On execution, we get:
Accuracy Comparison
Once the training process of all three predictors completes, we see the accuracy values.
- For the base table, we get an accuracy value of
0.963
. - For the base table with two more data columns, we get an accuracy value of
0.965
. The accuracy value increased, as expected. - For the base table with four more data columns, we get an accuracy value of
0.982
. The accuracy value increased again, as expected.
True vs Predicted Price Comparison
Let’s compare how close the predicted price values are to the true price.
The prices predicted by the third predictor, having the highest accuracy value, are the closest to the true price, as expected.
Example: Joining Data Tables
Introduction
We start by creating a predictor from the car_sales
table. Then, we add more data by joining the car_sales
and car_info
tables. We create a predictor based on the car_sales_info
view.
Let’s get started.
Let’s Run the Codes
Here, we go through the codes using partial tables and the full table after joining the data.
Data Setup
Here is the car_sales
table:
On execution, we get:
Where:
Name | Description |
---|---|
model | Model of the car. |
year | Year of production. |
price | Price of the car. |
transmission | Transmission (Manual , or Automatic , or Semi-Auto ). |
mileage | Mileage of the car. |
fueltype | Fuel type of the car. |
tax | Tax. |
And here is the car_info
table:
On execution, we get:
Where:
Name | Description |
---|---|
model | Model of the car. |
year | Year of production. |
transmission | Transmission (Manual , or Automatic , or Semi-Auto ). |
fueltype | Fuel type of the car. |
mpg | Miles per gallon. |
enginesize | Engine size of the car. |
Let’s join the car_sales
and car_info
tables on the model
, year
, transmission
, and fueltype
columns.
Nested SELECT
Statements Please note that we use the nested SELECT
statement in order to trigger native query at the MindsDB Cloud Editor. Here, the example_db
database is a PostgreSQL database, so we trigger PostgreSQL-native syntax.
On execution, we get:
Now, we create a view based on the JOIN
query:
On execution, we get:
Let’s verify the view by selecting from it.
On execution, we get:
Creating Predictors
Let’s create a predictor with the car_sales
table as input data.
On execution, we get:
Now, let’s create a predictor for the table that is a JOIN
between the car_sales
and car_info
tables.
On execution, we get:
Predictor Status
Next, we check the status of both predictors.
We start with the predictor based on the partial table.
On execution, we get:
And now, for the predictor based on the full table.
On execution, we get:
Accuracy Comparison
The accuracy values are 0.912 for both the predictors. The predictor already learns how the combination of model+year+transmission+fueltype
affects the price, so joining more data columns doesn’t play a role in this particular example.