A model is automatically deployed and used for predictions if its key metric (R2 for regression, F1 for classification) is improved during training over the previous version. Alternatively, if you want to manage deploys manually, you can always change which model is currently responsible for making predictions.
content_copy
pgml.deploy(
project_name TEXT,
strategy TEXT DEFAULT 'best_score',
algorithm TEXT DEFAULT NULL
)
Parameter |
Example |
Description |
project_name |
'My First PostgresML Project' |
The name of the project used in pgml.train() and pgml.predict() . |
strategy |
'rollback' |
The deployment strategy to use for this deployment. |
algorithm |
'xgboost' |
Restrict the deployment to a specific algorithm. Useful when training on multiple algorithms and hyperparameters at the same time. |
There are 3 different deployment strategies available:
Strategy |
Description |
most_recent |
The most recently trained model for this project is immediately deployed, regardless of metrics. |
best_score |
The model that achieved the best key metric score is immediately deployed. |
rollback |
The model that was deployed before to the current one is deployed. |
The default deployment behavior allows any algorithm to qualify. It's automatically used during training, but can be manually executed as well:
content_copy
SELECT * FROM pgml.deploy(
'Handwritten Digit Image Classifier',
strategy => 'best_score'
);
content_copy
project | strategy | algorithm
------------------------------------+------------+-----------
Handwritten Digit Image Classifier | best_score | xgboost
(1 row)
Deployment candidates can be restricted to a specific algorithm by including the algorithm
parameter. This is useful when you're training multiple algorithms using different hyperparameters and want to restrict the deployment a single algorithm only:
content_copy
SELECT * FROM pgml.deploy(
project_name => 'Handwritten Digit Image Classifier',
strategy => 'best_score',
algorithm => 'svm'
);
content_copy
project_name | strategy | algorithm
------------------------------------+----------------+----------------
Handwritten Digit Image Classifier | classification | svm
(1 row)
In case the new model isn't performing well in production, it's easy to rollback to the previous version. A rollback creates a new deployment for the old model. Multiple rollbacks in a row will oscillate between the two most recently deployed models, making rollbacks a safe and reversible operation.
content_copy
SELECT * FROM pgml.deploy(
'Handwritten Digit Image Classifier',
strategy => 'rollback'
);
content_copy
project | strategy | algorithm
------------------------------------+----------+-----------
Handwritten Digit Image Classifier | rollback | linear
(1 row)
Rollbacks are actually new deployments, so issuing two rollbacks in a row will leave you back with the original model, making rollback safely undoable.
content_copy
SELECT * FROM pgml.deploy(
'Handwritten Digit Image Classifier',
strategy => 'rollback'
);
content_copy
project | strategy | algorithm
------------------------------------+----------+-----------
Handwritten Digit Image Classifier | rollback | xgboost
(1 row)
In the case you need to deploy an exact model that is not the most_recent
or best_score
, you may deploy a model by id. Model id's can be found in the pgml.models
table.
content_copy
SELECT * FROM pgml.deploy(12);
content_copy
project | strategy | algorithm
------------------------------------+----------+-----------
Handwritten Digit Image Classifier | specific | xgboost
(1 row)