palladium package¶
Submodules¶
palladium.R module¶
palladium.cache module¶
The cache module provides caching utilities in order to provide
faster access to data which is needed repeatedly. The disk cache
(diskcache
) which is primarily used during development when
loading data from the local harddisk is faster than querying a remote
database.
-
class
palladium.cache.
abstractcache
(compute_key=None, ignore=False)¶ Bases:
object
An abstract class for providing basic functionality for caching function calls. It contains the handling of keys used for caching objects.
-
palladium.cache.
compute_key_attrs
(attrs)¶
-
class
palladium.cache.
diskcache
(*args, filename_tmpl=None, **kwargs)¶ Bases:
palladium.cache.abstractcache
The disk cache stores results of function calls as pickled files to disk. Usually used during development and evaluation to save costly DB interactions in repeated calls with the same data.
Note: Should changes to the database or to your functions require you to purge existing cached values, then those cache files are found in the location defined in
filename_tmpl
.
-
class
palladium.cache.
picklediskcache
(*args, filename_tmpl=None, **kwargs)¶ Bases:
palladium.cache.diskcache
Same as diskcache, except that standard pickle is used instead of joblib’s pickle functionality.
-
dump
(value, filename)¶
-
load
(filename)¶
-
palladium.config module¶
-
class
palladium.config.
Config
¶ Bases:
dict
A dictionary that represents the app’s configuration.
Tries to send a more user friendly message in case of KeyError.
-
class
palladium.config.
CopyHandler
(configs)¶ Bases:
object
-
class
palladium.config.
PythonHandler
(config)¶ Bases:
object
-
palladium.config.
get_config
(**extra)¶
-
palladium.config.
initialize_config
(**extra)¶
-
palladium.config.
process_config
(*configs, handlers0=<function _handlers_phase0>, handlers1=<function _handlers_phase1>, handlers2=<function _handlers_phase2>)¶
palladium.dataset module¶
DatasetLoader
implementations.
-
class
palladium.dataset.
EmptyDatasetLoader
¶ Bases:
palladium.interfaces.DatasetLoader
This
DatasetLoader
can be used if no actual data should be loaded. Returns a(None, None)
tuple.
-
class
palladium.dataset.
SQL
(url, sql, target_column=None, ndarray=True, **kwargs)¶ Bases:
palladium.interfaces.DatasetLoader
A
DatasetLoader
that usespandas.io.sql.read_sql()
to load data from an SQL database. Supports all databases that SQLAlchemy has support for.
-
class
palladium.dataset.
ScheduledDatasetLoader
(impl, update_cache_rrule)¶ Bases:
palladium.interfaces.DatasetLoader
A
DatasetLoader
that loads periodically data into RAM to make it available to the prediction server inside theprocess_store
.ScheduledDatasetLoader
wraps anotherDatasetLoader
class that it uses to do the actual loading of the data.An update_cache_rrule is used to define how often data should be loaded anew.
This class’
read()
read method never calls the underlying dataset loader. It will only ever fetch the data from the in-memory cache.-
cache
= {'process_metadata': {}}¶
-
initialize_component
(config)¶
-
update_cache
(*args, **kwargs)¶
-
-
class
palladium.dataset.
Table
(path, target_column=None, ndarray=True, **kwargs)¶ Bases:
palladium.interfaces.DatasetLoader
A
DatasetLoader
that usespandas.io.parsers.read_table()
to load data from a file or URL.
palladium.eval module¶
Utilities for testing the performance of a trained model.
-
palladium.eval.
list
(model_persister)¶
-
palladium.eval.
list_cmd
(argv=['-T', '-b', 'readthedocs', '-d', '_build/doctrees-readthedocs', '-D', 'language=en', '.', '_build/html'])¶ List information about available models.
Uses the ‘model_persister’ from the configuration to display a list of models and their metadata.
- Usage:
- pld-list [options]
- Options:
- -h –help Show this screen.
-
palladium.eval.
test
(dataset_loader_test, model_persister, scoring=None, model_version=None)¶
-
palladium.eval.
test_cmd
(argv=['-T', '-b', 'readthedocs', '-d', '_build/doctrees-readthedocs', '-D', 'language=en', '.', '_build/html'])¶ Test a model.
Uses ‘dataset_loader_test’ and ‘model_persister’ from the configuration to load a test dataset to test the accuracy of a trained model with.
- Usage:
- pld-test [options]
- Options:
-h –help Show this screen.
--model-version=<version> The version of the model to be tested. If not specified, the newest model will be used.
palladium.fit module¶
palladium.interfaces module¶
Interfaces defining the behaviour of Palladium’s components.
-
class
palladium.interfaces.
CrossValidationGenerator
¶ Bases:
object
A
CrossValidationGenerator
provides train/test indices to split data in train and validation sets.CrossValidationGenerator
corresponds to the cross validation generator interface of scikit-learn.
-
class
palladium.interfaces.
DatasetLoader
¶ Bases:
object
A
DatasetLoader
is responsible for loading datasets for use in training and evaluation.
-
class
palladium.interfaces.
DatasetLoaderMeta
(name, bases, attrs, **kwargs)¶ Bases:
abc.ABCMeta
-
class
palladium.interfaces.
Model
¶ Bases:
Dummy
A
Model
can befit()
to data and can be used topredict()
data.Model
corresponds to the estimators interface of scikit-learn.-
fit
(X, y=None)¶ Fit to data array X and possibly a target array y.
Returns: self
-
predict
(X, **kw)¶ Predict classes for data array X with shape n x m.
Some models may accept additional keyword arguments.
Returns: A numpy array of length n with the predicted classes (for classification problems) or numeric values (for regression problems). Raises: May raise a PredictError
to indicate that some condition made it impossible to deliver a prediction.
-
predict_proba
(X, **kw)¶ Predict probabilities for data array X with shape n x m.
Returns: A numpy array of length n x c with a list class probabilities per sample. Raises: NotImplementedError
if not applicable.
-
-
class
palladium.interfaces.
ModelPersister
¶ Bases:
object
-
activate
(version)¶ Set the model with the given version to be the active one.
Implies that any previously active model becomes inactive.
Parameters: version (str) – The version of the model that’s activated. Raises: LookupError if no model with given version exists.
-
delete
(version)¶ Delete the model with the given version from the database.
Parameters: version (str) – The version of the model that’s activated. Raises: LookupError if no model with given version exists.
-
list_models
()¶ List metadata of all available models.
Returns: A list of dicts, with each dict containing information about one of the available models. Each dict is guaranteed to contain the version
key, which is the same version number thatModelPersister.read()
accepts for loading specific models.
-
list_properties
()¶ List properties of
ModelPersister
itself.Returns: A dictionary of key and value pairs, where both keys and values are of type str
. Properties will usually includeactive-model
anddb-version
entries.
-
read
(version=None)¶ Returns a
Model
instance.Parameters: version (str) – version may be used to read a specific version of a model. If version is None
, returns the active model.Returns: The model object. Raises: LookupError if no model was available.
-
upgrade
(from_version=None, to_version='n/a')¶ Upgrade the underlying database to the latest version.
Newer versions of Palladium may require changes to the
ModelPersister
‘s database. This method provides an opportunity to run the necessary upgrade steps.It’s the
ModelPersister
‘s responsibility to keep track of the Palladium version that was used to create and upgrade its database, and thus to determine the upgrade steps necessary.
-
write
(model)¶ Persists a
Model
and returns a new version number.It is the
ModelPersister
‘s responsibility to annotate the ‘version’ information onto the model before it is saved.The new model will initially be inactive. Use
ModelPersister.activate()
to activate the model.Returns: The new model’s version identifier.
-
-
class
palladium.interfaces.
ModelPersisterMeta
(name, bases, attrs, **kwargs)¶ Bases:
abc.ABCMeta
-
exception
palladium.interfaces.
PredictError
(error_message, error_code=-1)¶ Bases:
Exception
Raised by
Model.predict()
to indicate that some condition made it impossible to deliver a prediction.
-
class
palladium.interfaces.
PredictService
¶ Bases:
object
Responsible for producing the output for the ‘/predict’ HTTP endpoint.
-
palladium.interfaces.
annotate
(obj, metadata=None)¶
palladium.julia module¶
-
class
palladium.julia.
AbstractModel
(fit_func, predict_func, fit_kwargs=None, predict_kwargs=None, encode_labels=False)¶ Bases:
palladium.interfaces.Model
-
fit
(X, y)¶
-
predict
(X)¶
-
-
class
palladium.julia.
ClassificationModel
(fit_func, predict_func, fit_kwargs=None, predict_kwargs=None, encode_labels=False)¶ Bases:
palladium.julia.AbstractModel
-
score
(X, y)¶
-
-
palladium.julia.
make_bridge
()¶
palladium.persistence module¶
ModelPersister
implementations.
-
class
palladium.persistence.
CachedUpdatePersister
(impl, update_cache_rrule=None, check_version=True)¶ Bases:
palladium.interfaces.ModelPersister
A
ModelPersister
that serves as a caching decorator around another ~palladium.interfaces.ModelPersister object.Calls to
read()
will look up a model from the globalprocess_store
, i.e. there is never any actual loading involved when callingread()
.To fill the
process_store
cache periodically using the return value of the underlyingModelPersister
‘sread
method, a dictionary containing keyword arguments todateutil.rrule.rrule
may be passed. The cache will then be filled periodically according to that recurrence rule.If no update_cache_rrule is used, the
CachedUpdatePersister
will call once and remember the return value of the underlyingModelPersister
‘sread
method during initialization.-
activate
(version)¶
-
cache
= {'process_metadata': {}}¶
-
delete
(version)¶
-
initialize_component
(config)¶
-
list_models
()¶
-
list_properties
()¶
-
read
(*args, **kwargs)¶
-
update_cache
(*args, **kwargs)¶
-
upgrade
(from_version=None, to_version='n/a')¶
-
write
(model)¶
-
-
class
palladium.persistence.
Database
(url, poolclass=None, chunk_size=104857600, table_postfix='')¶ Bases:
palladium.interfaces.ModelPersister
A
ModelPersister
that pickles models into an SQL database.-
DBModelChunkClass
(Base)¶
-
DBModelClass
(Base)¶
-
PropertyClass
(Base)¶
-
activate
(version)¶
-
create_orm_classes
()¶
-
delete
(version)¶
-
list_models
()¶
-
list_properties
()¶
-
read
(version=None)¶
-
upgrade
(from_version=None, to_version='n/a')¶
-
upgrade_steps
= <palladium.persistence.UpgradeSteps object>¶
-
write
(model)¶
-
-
class
palladium.persistence.
DatabaseCLOB
(url, poolclass=None, chunk_size=104857600, table_postfix='')¶ Bases:
palladium.persistence.Database
A
ModelPersister
derived fromDatabase
, with only the slight difference of using CLOB instead of BLOB to store the pickle data.Use when BLOB is not available.
-
DBModelChunkClass
(Base)¶
-
read
(version=None)¶
-
write
(model)¶
-
-
class
palladium.persistence.
File
(path)¶ Bases:
palladium.persistence.FileLike
A
ModelPersister
that pickles models onto the file system, into a given directory.-
read
(version=None)¶
-
write
(model)¶
-
-
class
palladium.persistence.
FileIO
¶ Bases:
palladium.persistence.FileLikeIO
-
exists
(path)¶
-
open
(path, mode='r')¶
-
remove
(path)¶
-
-
class
palladium.persistence.
FileLike
(path, io)¶ Bases:
palladium.interfaces.ModelPersister
A
ModelPersister
that pickles models through file-like handles.An argument
io
is used to access low level file handle operations.-
activate
(version)¶
-
delete
(version)¶
-
list_models
()¶
-
list_properties
()¶
-
read
(version=None)¶
-
upgrade
(from_version=None, to_version='n/a')¶
-
upgrade_steps
= <palladium.persistence.UpgradeSteps object>¶
-
write
(model)¶
-
-
class
palladium.persistence.
FileLikeIO
¶ Bases:
object
Used by
FileLike
to access low level file handle operations.-
exists
(path)¶ Test whether a path exists
For normal files, the implementation is:
`python return os.path.exists(path) `
-
open
(path, mode='r')¶ Return a file handle
For normal files, the implementation is:
`python return open(path, mode) `
-
remove
(path)¶ Remove a file
For normal files, the implementation is:
`python os.remove(path) `
-
-
class
palladium.persistence.
Rest
(url, auth)¶ Bases:
palladium.persistence.FileLike
-
read
(version=None)¶
-
write
(model)¶
-
-
class
palladium.persistence.
RestIO
(auth)¶ Bases:
palladium.persistence.FileLikeIO
-
exists
(path)¶
-
open
(path, mode='r')¶
-
remove
(path)¶
-
palladium.server module¶
palladium.util module¶
Assorted utilties.
-
palladium.util.
Partial
(func, **kwargs)¶ Allows the use of partially applied functions in the configuration.
-
class
palladium.util.
PluggableDecorator
(decorator_config_name)¶ Bases:
object
-
class
palladium.util.
ProcessStore
(*args, **kwargs)¶ Bases:
collections.UserDict
-
class
palladium.util.
RruleThread
(func, rrule, sleep_between_checks=60)¶ Bases:
threading.Thread
Calls a given function in intervals defined by given recurrence rules (from datetuil.rrule).
-
run
()¶
-
-
palladium.util.
apply_kwargs
(func, **kwargs)¶ Call func with kwargs, but only those kwargs that it accepts.
-
palladium.util.
args_from_config
(func)¶ Decorator that injects parameters from the configuration.
-
palladium.util.
get_metadata
(error_code=0, error_message=None, status='OK')¶
-
palladium.util.
memory_usage_psutil
()¶ Return the current process memory usage in MB.
-
palladium.util.
resolve_dotted_name
(dotted_name)¶
-
palladium.util.
run_job
(func, **params)¶
-
palladium.util.
session_scope
(session)¶ Provide a transactional scope around a series of operations.
-
palladium.util.
timer
(log=None, message=None)¶
-
palladium.util.
upgrade
(model_persister, from_version=None, to_version=None)¶
-
palladium.util.
upgrade_cmd
(argv=['-T', '-b', 'readthedocs', '-d', '_build/doctrees-readthedocs', '-D', 'language=en', '.', '_build/html'])¶ Upgrade the database to the latest version.
- Usage:
- pld-ugprade [options]
- Options:
--from=<v> Upgrade from a specific version, overriding the version stored in the database. --to=<v> Upgrade to a specific version instead of the latest version. -h –help Show this screen.
-
palladium.util.
version_cmd
(argv=['-T', '-b', 'readthedocs', '-d', '_build/doctrees-readthedocs', '-D', 'language=en', '.', '_build/html'])¶ Print the version number of Palladium.
- Usage:
- pld-version [options]
- Options:
- -h –help Show this screen.