Description
TheCREATE VIEW statement creates a view, which is a great way to do data preparation in MindsDB. A VIEW is a saved SELECT statement, which is executed every time we call this view.
Syntax
Here is the syntax:| Name | Description |
|---|---|
project_name | Name of the project to store the view. |
view_name | Name of the view. |
a.column_name, ... | Columns of the data source table that are the input for the model to make predictions. |
p.model_column | Name of the target column to be predicted. |
integration_name.table_name | Data source table name along with the integration where it resides. |
predictor_name | Name of the model. |
Example
Below is the query that creates and trains thehome_rentals_model model to predict the rental_price value. The inner SELECT statement provides all real estate listing data used to train the model.
JOIN the home_rentals_data table with the home_rentals_model model to make predictions. By creating a view (using the CREATE VIEW statement) that is based on the SELECT statement joining the data and model tables, we create an AI Table.
Here, the SELECT statement joins the data source table and the model table. The input data for making predictions consists of the sqft, number_of_bathrooms, and location columns. These are joined with the rental_price column that stores predicted values.
Dataset for Training and Dataset for JoiningIn this example, we used the same dataset (Now, having the
integration.home_rentals_data) for training the model (see the CREATE MODEL statement above) and for joining with the model to make predictions (see the CREATE VIEW statement above). It doesn’t happen like that in real-world scenarios.
Normally, you use the old data to train the model, and then you join the new data with this model to make predictions.Consider the old_data dataset that stores data from the years 2019-2021 and the new_data dataset that stores data from the year 2022.We train the model with the old_data dataset like this:data_model model trained using the old_data dataset, we can join this model with the new_data dataset to make predictions like this:USING VIEW
Examples to use view- Complex select on view (it is grouping in this example).
- Creating predictor from view
- Using predictor with view
From Our CommunityCheck out the article created by our community:
- Article on Creating Views with MindsDB by Rutam Prita Mishra