isotree (version 0.2.10)

load.isotree.model: Load an Isolation Forest model exported from Python

Description

Loads a serialized Isolation Forest model as produced and exported by the Python version of this package. Note that the metadata must be something importable in R - e.g. column names must be valid for R (numbers are not valid names for R). It's recommended to visually inspect the `.metadata` file in any case.

This function is not meant to be used for passing models to and from R - in such case, one can use `saveRDS` and `readRDS` instead as they will likely result in smaller file sizes (although this function will still work correctly for serialization within R).

Usage

load.isotree.model(file)

Arguments

file

Path to the saved isolation forest model along with its metadata file, and imputer file if produced. Must be a file path, not a file connection.

Value

An isolation forest model, as if it had been constructed through isolation.forest.

Details

Internally, this function uses `readr::read_file_raw` (from the `readr` package) and `jsonlite::fromJSON` (from the `jsonlite` package). Be sure to have those installed and that the files are readable through them.

Note: If the model was fit to a ``DataFrame`` using Pandas' own Boolean types, take a look at the metadata to check if these columns will be taken as booleans (R logicals) or as categoricals with string values `"True"` or `"False"`.

If using this function to de-serialize a model in a production system, one might want to delete the serialized bytes inside the object afterwards in order to free up memory. These are under `model$cpp_obj$serialized` (plus `model$cpp_obj$imp_ser` if building with imputer) - e.g.: `model$cpp_obj$serialized = NULL; model$cpp_obj$imp_ser = NULL; gc()`.

See Also

export.isotree.model unpack.isolation.forest