module mlapp.mlstorage

Inheritance diagram of lightmlrestapi.mlapp.mlstorage

Short summary

module lightmlrestapi.mlapp.mlstorage

Machine Learning Post request

source on GitHub

Classes

class truncated documentation
AlreadyExistsException Exception raised when a project already exists.
MLStorage Stores machine learned models into folders. The storages expects to find at least one python following the …
ZipStorage Stores and restores zipped files.

Methods

method truncated documentation
__init__  
__init__  
_check_name A name is valid if it is a variable name or a filename if data is True.
_check_name A name is valid if it is a variable name or a filename if data is True.
_import Imports the main module for one model.
_makedirs Creates a subfolder and add a file __init__.py. The function overwrites it file __init__.py to let …
_makedirs Creates a subfolder and add a file __init__.py. The function overwrites it file __init__.py to let …
add Adds a project based on the data. A project which already exists cannot be added.
add Adds a project based on the data. A project which already exists cannot be added.
call_predict Calls method restapi_predict from a stored script python.
call_version 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.
enumerate_names Returns the list of sub folders.
enumerate_names Returns the list of sub folders.
exists Tells if project name exists.
exists Tells if project name exists.
get Retrieves a project based on its name.
get Retrieves a project based on its name.
get_full_name Returns the full name of a project.
get_full_name Returns the full name of a project.
get_metadata Restores the data procuded by verify_data.
get_metadata Restores the data procuded by verify_data.
load_model Loads a model into the cache if not loaded and returns it.
verify_data Performs verifications to ensure the data to store is ok. The storages expects to find at least one script …
verify_data Performs verifications to ensure the data to store is ok.

Documentation

Machine Learning Post request

source on GitHub

exception lightmlrestapi.mlapp.mlstorage.AlreadyExistsException[source]

Bases: Exception

Exception raised when a project already exists.

source on GitHub

class lightmlrestapi.mlapp.mlstorage.MLStorage(folder, cache_size=10)[source]

Bases: lightmlrestapi.mlapp.mlstorage.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.

source on GitHub

Parameters:
  • folder – folder
  • cache_size – cache size

source on GitHub

__init__(folder, cache_size=10)[source]
Parameters:
  • folder – folder
  • cache_size – cache size

source on GitHub

_import(name)[source]

Imports the main module for one model.

Parameters:name – model name
Returns:imported module

source on GitHub

call_predict(name, data, version=False, was_loaded=False, loaded_model=None)[source]

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

source on GitHub

call_version(name)[source]

Calls method restapi_version from a stored script python.

source on GitHub

empty_cache()[source]

Removes one place in the cache if the cache is full. Sort them by last access.

source on GitHub

load_model(name, was_loaded=False)[source]

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.

source on GitHub

verify_data(data)[source]

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

source on GitHub

class lightmlrestapi.mlapp.mlstorage.ZipStorage(folder)[source]

Bases: object

Stores and restores zipped files.

source on GitHub

Parameters:folder – folder

source on GitHub

__init__(folder)[source]
Parameters:folder – folder

source on GitHub

_check_name(name, data=False)[source]

A name is valid if it is a variable name or a filename if data is True.

source on GitHub

_makedirs(subfold)[source]

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.

source on GitHub

add(name, data)[source]

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

source on GitHub

enumerate_names()[source]

Returns the list of sub folders.

source on GitHub

exists(name)[source]

Tells if project name exists.

Parameters:name – name
Returns:boolean

source on GitHub

get(name)[source]

Retrieves a project based on its name.

Parameters:name – project name
Returns:data

source on GitHub

get_full_name(name)[source]

Returns the full name of a project.

Parameters:name – project name
Returns:full name

source on GitHub

get_metadata(name)[source]

Restores the data procuded by verify_data.

source on GitHub

verify_data(data)[source]

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

source on GitHub