spines.models

Models for the spines library.

class spines.models.Model(*args, **kwargs)[source]

Bases: object

Model class

build(*args, **kwargs) → None[source]

Builds the model

Parameters
  • args (optional) – Arguments to use in building the model.

  • kwargs (optional) – Keyword arguments to use in building the model.

error(*args, **kwargs) → float[source]

Returns the error measure of the model for the given data

Parameters
  • args (optional) – Additional arguments to pass to the error call.

  • kwargs (optional) – Additional keyword-arguments to pass to the error call.

Returns

Error for the model on the given inputs and outputs.

Return type

float

fit(*args, **kwargs) → None[source]

Fits the model

Parameters
  • args (optional) – Arguments to use in fit call.

  • kwargs (optional) – Any additional keyword arguments to use in fit call.

get_hyper_params() → Dict[str, object][source]

Gets the current hyper-parameter values

Returns

Copy of the currently set hyper-parameter values.

Return type

dict

get_params() → dict[source]

Gets a copy of this models parameters

Returns

Copy of currently set parameter names and values.

Return type

dict

hyper_parameters

Hyper-parameters which are currently set.

Type

ParameterStore

classmethod load(path: str, fmt: [<class 'str'>, None] = None, new: bool = False) → Type[Model][source]

Loads a saved model instance

Loads saved model parameters and hyper_params as well as any serialized model-specific objects from a saved version with the tag specified (from the base project_dir).

Parameters
  • path (str) – Path to load the model from.

  • fmt (str or None) – Format of the file to load (if None it will be inferred).

  • new (bool, optional) – Whether to create a new object from this class or use the saved object class (default is False).

Returns

Model loaded from disk.

Return type

Model

parameters

Parameters which are currently set.

Type

ParameterStore

predict(*args, **kwargs)[source]

Predict outputs for the given inputs

Parameters
  • args (optional) – Additional arguments to pass to predict call.

  • kwargs (optional) – Additional keyword arguments to pass to predict call.

Returns

Predictions from the given data.

Return type

object

save(path: str, fmt: [<class 'str'>, None] = None, overwrite_existing: bool = False) → str[source]

Saves this model

Saves this model’s parameters, hyper_params as well as any other data required to reconstruct this model. Saves this data with the given unique tag name.

Parameters
  • path (str) – File path to save the model to.

  • fmt (str) – File output format to use.

  • overwrite_existing (bool, optional) – Whether to overwrite any existing saved model with the same path (Default is False).

Returns

The path to the saved file.

Return type

str

Raises

NotImplementedError – If the specified fmt is not supported.

set_hyper_parameter(name: str, value) → None[source]

Sets a hyper-parameter value

Sets a hyper-parameter’s value if the given hyper_param and value are valid.

Parameters
  • name (str) – Hyper-parameter to set value for.

  • value – Value to set.

Raises
set_hyper_params(**hyper_params) → None[source]

Sets the values of this model’s hyper-parameters

Parameters

hyper_params – Hyper-parameter values to set.

Raises

InvalidParameterException – If one of the given hyper-parameter values is not valid.

set_parameter(name: str, value) → None[source]

Sets a parameter value

Will add the given param and value to the parameters if they are valid, throws an exception if they are not.

Parameters
  • name (str) – Parameter to set the value for.

  • value – Value to set.

Raises

InvalidParameterException – If the given name or value are not valid.

See also

parameters()

set_params(**params) → None[source]

Sets the values for this model’s parameters

Parameters

params – Parameters and values to set.

Raises

InvalidParameterException – If the given name or value are not valid.

unset_hyper_parameter(name: str)[source]

Un-sets a hyper-parameter

Un-sets the specified hyper-parameter’s value from the set of hyper-parameters and returns the previously set value.

Parameters

name (str) – Name of the hyper-parameter to clear the value for.

Returns

Previously set value of the hyper-parameter.

Return type

object

Raises

MissingParameterException – If the given name hyper-parameter does not exist.

unset_parameter(name: str) → object[source]

Unsets a parameter value

Removes the specified parameter’s value from the parameter values if it is part of the parameter set and returns its current value.

Parameters

name (str) – Name of the parameter whose value needs to be un-set.

Returns

Previously set value of the parameter.

Return type

object

Raises

MissingParameterException – If the parameter to remove does not exist in the set of parameters.

See also

parameters()