spines¶
Spines
Skeletons for parameterized models.
-
class
spines.
Model
(*args, **kwargs)[source]¶ Bases:
spines.transforms.base.Transform
Spines primary Model class
-
fit
(*args, **kwargs) → None[source]¶ Fits the model
Generally this method is used for a single iteration of model fitting (and for simple models this may be the only call which is required). The
train
method can call this function multiple times and update the model iteratively (where that approach is appropriate).- Parameters
args (optional) – Arguments to use in fit call.
kwargs (optional) – Any additional keyword arguments to use in fit call.
- Returns
Either returns None if adjustments to the model’s parameters happen internally, otherwise returns the dictionary of updated parameters to apply.
- Return type
None
ordict
See also
train()
,transform()
-
get_hyper_params
() → Dict[str, Any][source]¶ Gets the current hyper-parameter values
- Returns
Copy of the currently set hyper-parameter values.
- Return type
dict
See also
-
hyper_parameters
¶ Hyper-parameters which are currently set.
- Type
-
predict
(*args, **kwargs) → Any[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
-
set_hyper_parameter
(name: str, value: Any) → 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
MissingParameterException – If the given name hyper-parameter does not exist.
InvalidParameterException – If the given value is not valid for the specified hyper-parameter.
See also
-
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.
-
transform
(*args, **kwargs) → Any[source]¶ Transforms the given input data
- Parameters
args (optional) – Additional arguments to pass to predict call.
kwargs (optional) – Additional keyword arguments to pass to predict call.
- Returns
Transformed inputs.
- Return type
object
-
unset_hyper_parameter
(name: str) → Any[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.
See also
-
-
class
spines.
Parameter
(*value_type, default: Optional[Any] = None, desc: Optional[str] = None)[source]¶ Bases:
object
Parameter class
- Parameters
value_type (
type
orIterable
oftype
) – The type(s) of values allowed for this parameter.default (object, optional) – Default value for this parameter, if any.
desc (str, optional) – Description for this parameter, if any.
-
check
(value: Any) → bool[source]¶ Checks the given value for validity
Based on this particular Parameter’s settings this method checks the given value to see if it’s in-line with the specifications.
- Parameters
value – Parameter value to check validity of.
- Returns
Whether or not the value is valid for the parameter.
- Return type
bool
See also
-
default
¶ Default value to use for this parameter.
- Type
object
-
desc
¶ Description of this parameter.
- Type
str
-
name
¶ Name of this parameter.
- Type
str
-
preprocess
(value: Any) → Any[source]¶ Pre-process/massage parameter values into correct type
This is used to try and convert parameter values to the allowed types (if possible). For instance the allowed type may be a
float
but the user provides1
, we would likely not want to break in that situation, but simply convert theint
given into afloat
. However, this can also be used to perform more complex initialization or customization on given parameter values, if needed.The default method is to try and cast the given value as the types given in this Parameter’s
_value_types
attribute and returning the first successful cast, otherwise returns the given input value.This method can be easily extended or overridden for custom Parameter classes to handle more complex value types.
- Parameters
value (object) – The value to pre-process for this parameter.
- Returns
The pre-processed value.
- Return type
object
Note
This method is, by default, only called if the given value fails this Parameter’s
check
call.See also
-
required
¶ Whether or not this parameter is required to be set.
- Type
bool
-
value_type
¶ The types of values allowed for this option.
- Type
tuple
-
class
spines.
HyperParameter
(*value_type, default: Optional[Any] = None, desc: Optional[str] = None)[source]¶ Bases:
spines.parameters.base.Parameter
Hyper-parameter
-
spines.
get_config
(setting: str = _MISSING, default: Any = _MISSING) → spines.config.core.Config[source]¶ Get the global spines configuration
- Parameters
setting (str, optional) – Setting(s) to get from the global configuration.
default (optional) – Value to return if setting is not set (if not given an error will occur if accessing a non-existant setting).
- Returns
The global configuration settings for the current spines project or the values for the settings given.
- Return type
Config
ordict
- Raises
ValueError – If the given setting(s) doesn’t exist and no default value is provided.
-
spines.
load_config
(*path, update: bool = False) → None[source]¶ Loads the global spines configuration
- Parameters
path (
str
(or multiple), optional) – File(s) to load the configuration from (defaults to the correct spines hierarchy for configuration files).update (bool, optional) – Update the current configuration as opposed to replacing it with the newly loaded on (default is
False
, replace it).