Create, Train, and Deploy a Model
Description
The CREATE MODEL
statement creates and trains a machine learning (ML) model.
Please note that the CREATE MODEL
statement is equivalent to the CREATE PREDICTOR
statement.
We are transitioning to the CREATE MODEL
statement, but the CREATE PREDICTOR
statement still works.
Syntax
Overview
Here is the full syntax:
Where:
Expressions | Description |
---|---|
project_name | Name of the project where the model is created. By default, the mindsdb project is used. |
predictor_name | Name of the model to be created. |
integration_name | Name of the integration created using the CREATE DATABASE statement or file upload. |
(SELECT column_name, ... FROM table_name) | Selecting data to be used for training and validation. |
target_column | Column to be predicted. |
ORDER BY sequential_column | Used in time series models. The column by which time series is ordered. It can be a date or anything that defines the sequence of events. |
GROUP BY partition_column | Used in time series models. It is optional. The column by which rows that make a partition are grouped. For example, if you want to forecast the inventory for all items in the store, you can partition the data by product_id , so each distinct product_id has its own time series. |
WINDOW int | Used in time series models. The number of rows to look back at when making a prediction. It comes after the rows are ordered by the column defined in ORDER BY and split into groups by the column(s) defined in GROUP BY . The WINDOW 10 syntax could be interpreted as “Always use the previous 10 rows”. |
HORIZON int | Used in time series models. It is optional. It defines the number of future predictions (it is 1 by default). However, the HORIZON parameter, besides defining the number of predictions, has an impact on the training procedure when using the Lightwood ML backend. For example, different mixers are selected depending on whether the HORIZON value is one or greater than one. |
engine_name | You can optionally provide an ML engine, based on which the model is created. |
tag_name | You can optionally provide a tag that is visible in the training_options column of the mindsdb.models table. |
Regression Models
Here is the syntax for regression models:
Please note that the FROM
clause is mandatory here.
The target_column
that will be predicted is a numerical value. The prediction values are not limited to a defined set of values, but can be any number from the given range of numbers.
Classification Models
Here is the syntax for classification models:
Please note that the FROM
clause is mandatory here.
The target_column
that will be predicted is a string value. The prediction values are limited to a defined set of values, such as Yes
and No
.
Time Series Models
Here is the syntax for time series models:
Please note that the FROM
clause is mandatory here.
Due to the nature of time series forecasting, you need to use the JOIN
statement and join the data table with the model table to get predictions.
NLP Models
Here is the syntax for using external models within MindsDB:
Please note that you don’t need to define the FROM
clause here. Instead, the input_column
is defined in the USING
clause.
It allows you to bring an external model, for example, from the Hugging Face model hub, and use it within MindsDB.
Example
Regression Models
Here is an example for regression models that uses data from a database:
On execution, we get:
Visit our tutorial on regression models to see the full example.
Classification Models
Here is an example for classification models that uses data from a file:
On execution, we get:
Visit our tutorial on classification models to see the full example.
Time Series Models
Here is an example for time series models that uses data from a file:
On execution, we get:
Visit our tutorial on time series models to see the full example.
NLP Models
Here is an example for the Hugging Face model:
On execution, we get:
Visit our page no how to bring Hugging Face models into MindsDB for more details.
Checking Model Status
After you run the CREATE MODEL
statement, you can check the status of the training process by querying the mindsdb.models
table.
On execution, we get: