EXPORT_MODELS
Exports machine learning models. Vertica supports three model formats:
-
Native Vertica (VERTICA_MODELS)
-
PMML
-
TensorFlow
This is a meta-function. You must call meta-functions in a top-level SELECT statement.
Behavior type
VolatileSyntax
EXPORT_MODELS ( 'output-dir', 'export-target' [ USING PARAMETERS category = 'model-category' ] )
Arguments
output-dir
- Absolute path of an output directory to store the exported models.
export-target
- Specifies which models to export as follows:
[schema.]{ model-name | * }
where
schema
optionally specifies to export models from the specified schema. If omitted, EXPORT_MODELS uses the default schema. Supply*
(asterisk) to export all models from the schema.
Parameters
category
- The category of models to export, one of the following:
-
VERTICA_MODELS
-
PMML
-
TENSORFLOW
EXPORT_MODELS exports models of the specified category according to the scope of the export operation—that is, whether it applies to a single model, or to all models within a schema. See Export Scope and Category Processing below.
Exported Files below describes the files that EXPORT_MODELS exports for each category.
If you omit this parameter, EXPORT_MODELS exports the model, or models in the specified schema, according to their model type.
-
Privileges
Superuser
Export scope and category processing
EXPORT_MODELS executes according to the following parameter settings:
-
Scope of the export operation: single model, or all models within a given schema
-
Category specified or omitted
The following table shows how these two parameters control the export process:
Export scope | If category specified... | If category omitted... |
---|---|---|
Single model | Convert the model to the specified category, provided the model and category are compatible; otherwise, return with a mismatch error. | Export the model according to model type. |
All models in schema | Export only models that are compatible with the specified category and issue mismatch warnings on all other models in the schema. | Export all models in the schema according to model type. |
Exported files
EXPORT_MODELS exports the following files for each model category:
Model category | Exported files |
---|---|
VERTICA_MODELS |
|
PMML |
|
TENSORFLOW |
|
Categories and compatible models
If EXPORT_MODELS specifies a single model and also sets the category
parameter, the function succeeds if the model type and category are compatible; otherwise, it returns with an error:
Model type | Compatible categories |
---|---|
PMML |
PMML |
TensorFlow |
TENSORFLOW |
VERTICA_MODELS |
PMML VERTICA_MODELS |
If EXPORT_MODELS specifies to export all models from a schema and sets a category, it issues a warning message on each model that is incompatible with that category. The function then continues to process remaining models in that schema.
EXPORT_MODELS logs all errors and warnings in output-dir
/export_log.json
.
Examples
Export models without changing their category:
-
Export model
myschema.mykmeansmodel
without changing its category:=> SELECT EXPORT_MODELS ('/home/dbadmin', 'myschema.mykmeansmodel'); EXPORT_MODELS ---------------- Success (1 row)
-
Export all models in schema
myschema
without changing their categories:=> SELECT EXPORT_MODELS ('/home/dbadmin', 'myschema.*'); EXPORT_MODELS ---------------- Success (1 row)
Export models that are compatible with the specified category:
Note
When you import a model of category VERTICA_MODELS trained in a different version of Vertica, Vertica automatically upgrades the model version to match that of the database. If this fails, you must run UPGRADE_MODEL.
If both methods fail, the model cannot be used for in-database scoring and cannot be exported as a PMML model.
-
The category is set to PMML. Models of type PMML and VERTICA_MODELS are compatible with the PMML category, so the export operation succeeds if
my_keans
is of either type:=> SELECT EXPORT_MODELS ('/tmp/', 'my_kmeans' USING PARAMETERS category='PMML');
-
The category is set to VERTICA_MODELS. Only models of type VERTICA_MODELS are compatible with the VERTICA_MODELS category, so the export operation succeeds only if
my_keans
is of that type:=> SELECT EXPORT_MODELS ('/tmp/', 'public.my_kmeans' USING PARAMETERS category='VERTICA_MODELS');
-
The category is set to TENSORFLOW. Only models of type TensorFlow are compatible with the TENSORFLOW category, so the model
tf_mnist_keras
must be of type TensorFlow:=> SELECT EXPORT_MODELS ('/tmp/', 'tf_mnist_keras', USING PARAMETERS category='TENSORFLOW'); export_models --------------- Success (1 row)
After exporting the TensorFlow model tf_mnist_keras, list the exported files:
$ ls tf_mnist_keras/
crc.json metadata.json mnist_keras.pb model.json tf_model_desc.json