Machine¶
A Machine is the central unity of a model, dataset, metadata and everything needed to create and build a ML model to be served by a deployment.
An example of a Machine
in the context of a YAML config, could be
the following:
- name: ct-23-0001
dataset:
tags:
- TAG 1
- TAG 2
- TAG 3
train_start_date: 2016-11-07T09:11:30+01:00
train_end_date: 2018-09-15T03:01:00+01:00
metadata:
arbitrary-key: arbitrary-value
model:
gordo.machine.model.anomaly.diff.DiffBasedAnomalyDetector:
base_estimator:
sklearn.pipeline.Pipeline:
steps:
- sklearn.preprocessing.MinMaxScaler
- gordo.machine.model.models.KerasAutoEncoder:
kind: feedforward_hourglass
And to construct this into a python object:
>>> from gordo.machine import Machine
>>> # `config` is the result of the parsed and loaded yaml element above
>>> machine = Machine.from_config(config, project_name='test-proj')
>>> machine.name
ct-23-0001
-
class
gordo.machine.machine.
Machine
(name: str, model: dict, dataset: Union[gordo_dataset.base.GordoBaseDataset, dict], project_name: str, evaluation: Optional[dict] = None, metadata: Union[dict, gordo.machine.metadata.metadata.Metadata, None] = None, runtime=None)[source]¶ Bases:
object
Represents a single machine in a config file
-
dataset
¶ Descriptor for attributes requiring type
gordo.workflow.config_elements.Dataset
-
classmethod
from_config
(config: Dict[str, Any], project_name: str, config_globals=None)[source]¶ Construct an instance from a block of YAML config file which represents a single Machine; loaded as a
dict
.- Parameters
config (dict) – The loaded block of config which represents a ‘Machine’ in YAML
project_name (str) – Name of the project this Machine belongs to.
config_globals – The block of config within the YAML file within globals
- Returns
- Return type
-
classmethod
from_dict
(d: dict) → gordo.machine.machine.Machine[source]¶ Get an instance from a dict taken from
to_dict()
-
host
¶ Descriptor for use in objects which require valid URL values. Where ‘valid URL values’ is Gordo’s version: alphanumeric with dashes.
Use:
class MySpecialClass: url_attribute = ValidUrlString() ... myspecialclass = MySpecialClass() myspecialclass.url_attribute = 'this-is-ok' myspecialclass.url_attribute = 'this will r@ise a ValueError'
-
metadata
¶ Descriptor for attributes requiring type Optional[dict]
-
model
¶ Descriptor for attributes requiring type Union[dict, str]
-
name
¶ Descriptor for use in objects which require valid URL values. Where ‘valid URL values’ is Gordo’s version: alphanumeric with dashes.
Use:
class MySpecialClass: url_attribute = ValidUrlString() ... myspecialclass = MySpecialClass() myspecialclass.url_attribute = 'this-is-ok' myspecialclass.url_attribute = 'this will r@ise a ValueError'
Finding assets for all of the tags according to information from the dataset metadata
- Parameters
tag_list (TagsList) –
- Returns
- Return type
List[SensorTag]
-
project_name
¶ Descriptor for use in objects which require valid URL values. Where ‘valid URL values’ is Gordo’s version: alphanumeric with dashes.
Use:
class MySpecialClass: url_attribute = ValidUrlString() ... myspecialclass = MySpecialClass() myspecialclass.url_attribute = 'this-is-ok' myspecialclass.url_attribute = 'this will r@ise a ValueError'
-
report
()[source]¶ Run any reporters in the machine’s runtime for the current state.
Reporters implement the
gordo.reporters.base.BaseReporter
and can be specified in a config file of the machine for example:runtime: reporters: - gordo.reporters.postgres.PostgresReporter: host: my-special-host
-
runtime
¶ Descriptor for runtime dict in a machine object. Must be a valid runtime, but also must contain server.resources.limits/requests.memory/cpu to be valid.
-
to_dict
()[source]¶ Convert to a
dict
representation along with all attributes which can also be converted to adict
. Can reload withfrom_dict()
-
-
class
gordo.machine.machine.
MachineEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoder
A JSONEncoder for machine objects, handling datetime.datetime objects as strings and handles any numpy numeric instances; both of which common in the
dict
representation of aMachine
Example
>>> from pytz import UTC >>> s = json.dumps({"now":datetime.now(tz=UTC)}, cls=MachineEncoder, indent=4) >>> s = '{"now": "2019-11-22 08:34:41.636356+"}'
Constructor for JSONEncoder, with sensible defaults.
If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.
If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.
If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.
If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.
If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.
If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.
If specified, separators should be an (item_separator, key_separator) tuple. The default is (‘, ‘, ‘: ‘) if indent is
None
and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a
TypeError
.-
default
(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-