Skip to content

Latest commit

 

History

History
120 lines (84 loc) · 5.13 KB

storing_and_loading_calculators.rst

File metadata and controls

120 lines (84 loc) · 5.13 KB

Storing and loading calculators

Fitting a calculator or estimator is only required when the reference data for a monitored model changes. To avoid unnecessary calculations and speed up (repeating) runs of NannyML, you can store the fitted calculators in a ~nannyml.io.store.base.Store.

Note

We currently support persisting objects to a local or remote filesystem such as S3, Google Cloud Storage buckets, or Azure Blob Storage. You can find some examples<storing_calculators_remote_examples> in the walkthrough.

Note

For more information on how to use this functionality with the CLI or container, check the configuration file documentation<cli_configuration_store>.

Just the code

Create the calculator and fit it on reference. Store the fitted calculator on a local disk.

In a new session load the stored calculator and use it.

Walkthrough

In the first part, we create a new ~nannyml.drift.univariate.calculator.UnivariateDriftCalculator and fit it to the reference data.

In this snippet, we will set up the ~nannyml.io.store.file_store.FilesystemStore. It is a class responsible for storing objects on a filesystem and retrieving it back. We will first illustrate creating a store using the local filesystem. The root_path parameter configures the directory on the filesystem that will be used as the root of our store. Additional directories and files can be created when actually storing objects.

We will now provide a directory on the local filesystem.

Because we are using the fsspec library under the covers we also support a lot of remote filesystems out of the box.

The following snippet shows how to use S3 as a backing filesystem. See AWS documentation to learn more about the required access key id and secret access key credentials.

This is how to use Google Cloud Storage as a backing system. See Google Cloud documentation to learn more about the required service account key credentials.

This snippet illustrates how to do this using Azure Blob Storage. See Azure support documentation to learn more about the required credentials.

The next step is using the ~nannyml.io.store.file_store.FilesystemStore to store our fitted calculator. To do this, we can provide an optional path string parameter. It allows us to set a custom subdirectory and file name. If no path is provided, a file will be created using a standard name within the root directory of the store.

This concludes the first part: storing the fitted calculator.

When running NannyML in a new session to perform calculations on analysis data (e.g., repeated on a daily basis), we can load the pre-fitted calculator from the store. But, first, we define the analysis data and declare the store:

Now we will use the store to load the pre-fitted calculator from the disk. By providing the optional as_type parameter, we can have the store check the type of the loaded object before returning it. If it is not an instance of as_type, the ~nannyml.io.store.base.Store.load method will raise a ~nannyml.exceptions.StoreException.

If nothing is found at the given path, the ~nannyml.io.store.base.Store.load method will return None.

What's Next

The ~nannyml.io.store.file_store.FilesystemStore can also be used when running NannyML using the CLI or as a container. You can learn how in the configuration file documentation<cli_configuration_store>.