Skip to main content

CREATE MODEL

CREATE MODEL is used to define and train a new Ludwig model configuration.

Syntax

CREATE [ OR REPLACE ] MODEL [ IF NOT EXISTS ] model_name
WITH CONFIG 'yaml_or_json'
{ FROM dataset_name | AS query }

Model name

A unique name for the model. This can later be referenced in PREDICT statements through use of the USING clause.

Dataset name

The name of the dataset to use for training. For flat files, this is the name of the dataset. If the table name is ambiguous, you can fully qualify with the connection name eg:

FROM connection_name.dataset_name

Config

A model can also be created from a YAML or JSON string of model configuration. See the Ludwig documentation for full details.

Examples

Let's take a look at how we can create a model with features, as well as the JSON config.

Create model with config

Create a model to predict survivors of the Titanic using a json string for configuration.

CREATE MODEL titanic_small
WITH CONFIG '{
"input_features": [
{"name": "PClass", "type": "category"},
{"name": "Sex", "type": "category"},
{"name": "Age", "type": "number", "preprocessing": {"missing_value_strategy": "fill_with_mean"}},
{"name": "SibSp", "type": "number"},
{"name": "Parch", "type": "number"},
{"name": "Fare", "type": "number", "preprocessing": {"missing_value_strategy": "fill_with_mean"}},
{"name": "Embarked", "type": "category"}
],
"output_features": [{"name": "Survived", "type": "binary"}],
"trainer": {"epochs": 2}
}'
FROM titanic