module mlapp.mlstorage
¶
Short summary¶
module lightmlrestapi.mlapp.mlstorage
Machine Learning Post request
Classes¶
class |
truncated documentation |
---|---|
Exception raised when a project already exists. |
|
Stores machine learned models into folders. The storages expects to find at least one python following the … |
|
Stores and restores zipped files. |
Methods¶
method |
truncated documentation |
---|---|
|
A name is valid if it is a variable name or a filename if data is True. |
A name is valid if it is a variable name or a filename if data is True. |
|
Imports the main module for one model. |
|
|
Creates a subfolder and add a file |
Creates a subfolder and add a file |
|
|
Adds a project based on the data. A project which already exists cannot be added. |
Adds a project based on the data. A project which already exists cannot be added. |
|
Calls method restapi_predict from a stored script python. |
|
Calls method restapi_version from a stored script python. |
|
Removes one place in the cache if the cache is full. Sort them by last access. |
|
|
Returns the list of sub folders. |
Returns the list of sub folders. |
|
|
Tells if project name exists. |
Tells if project name exists. |
|
|
Retrieves a project based on its name. |
Retrieves a project based on its name. |
|
|
Returns the full name of a project. |
Returns the full name of a project. |
|
|
Restores the data procuded by verify_data. |
Restores the data procuded by verify_data. |
|
Loads a model into the cache if not loaded and returns it. |
|
Performs verifications to ensure the data to store is ok. The storages expects to find at least one script … |
|
Performs verifications to ensure the data to store is ok. |
Documentation¶
Machine Learning Post request
- exception lightmlrestapi.mlapp.mlstorage.AlreadyExistsException¶
Bases:
Exception
Exception raised when a project already exists.
- class lightmlrestapi.mlapp.mlstorage.MLStorage(folder, cache_size=10)¶
Bases:
ZipStorage
Stores machine learned models into folders. The storages expects to find at least one python following the specifications described at Implement your predict function. More template for actionable machine learned models through the following template: Templates.
- Parameters:
folder – folder
cache_size – cache size
- __init__(folder, cache_size=10)¶
- Parameters:
folder – folder
cache_size – cache size
- _import(name)¶
Imports the main module for one model.
- Parameters:
name – model name
- Returns:
imported module
- call_predict(name, data, version=False, was_loaded=False, loaded_model=None)¶
Calls method restapi_predict from a stored script python.
- Parameters:
name – model name
data – input data
version – returns the version as well
was_loaded – if True, return if the model was loaded again
loaded_model – skip cached model if exists, should be the result of a previous call to
loaded_model()
- Returns:
predictions or predictions, version
- call_version(name)¶
Calls method restapi_version from a stored script python.
- empty_cache()¶
Removes one place in the cache if the cache is full. Sort them by last access.
- load_model(name, was_loaded=False)¶
Loads a model into the cache if not loaded and returns it.
- Parameters:
name – cache name
was_loaded – if True, tells if the model was loaded again
- Returns:
dictionary with keys: last, model, module.
- verify_data(data)¶
Performs verifications to ensure the data to store is ok. The storages expects to find at least one script python with
- Parameters:
data – dictionary
- Returns:
python file which describes the model
@raises raises an exception if not ok
- class lightmlrestapi.mlapp.mlstorage.ZipStorage(folder)¶
Bases:
object
Stores and restores zipped files.
- Parameters:
folder – folder
- __init__(folder)¶
- Parameters:
folder – folder
- _check_name(name, data=False)¶
A name is valid if it is a variable name or a filename if data is True.
- _makedirs(subfold)¶
Creates a subfolder and add a file
__init__.py
. The function overwrites it file__init__.py
to let the interpreter know there was some changes.
- add(name, data)¶
Adds a project based on the data. A project which already exists cannot be added.
- Parameters:
name – project name, should only contain ascii characters +
'/'
data – dictionary or bytes produced by function
zip_dict
- enumerate_names()¶
Returns the list of sub folders.
- exists(name)¶
Tells if project name exists.
- Parameters:
name – name
- Returns:
boolean
- get(name)¶
Retrieves a project based on its name.
- Parameters:
name – project name
- Returns:
data
- get_full_name(name)¶
Returns the full name of a project.
- Parameters:
name – project name
- Returns:
full name
- get_metadata(name)¶
Restores the data procuded by verify_data.
- verify_data(data)¶
Performs verifications to ensure the data to store is ok.
- Parameters:
data – dictionary
- Returns:
None or information about the data
@raises raises an exception if not ok