proficloud.ml package

Submodules

proficloud.ml.AbstractModel module

class proficloud.ml.AbstractModel.AbstractModelClass

Bases: abc.ABC

This is the base Class for Models. It provides a standard interface with train, predict, predict_sample and summary methods for the model. It further provides save and load functionality.

static load (file_name)

Load model from json file.

Parameters:

file_name (str) – Source file name.

Returns:

Model instance

Return type:

AbstractModelClass

abstract predict (data)

This is the method to predict a whole dataset. The data parameter is the dataframe to use. Must be implemented by Model.

Parameters:

data (pandas.DataFrame) – Dataframe to evaluate

Returns:

Returns list with an entry for each row of the dataframe.

Return type:

list

abstract predict_sample (sample)

This is the method to predict a single sample. The sample parameter is sample to predict. Must be implemented by Model.

Parameters:

sample (pandas.Series / numpy.array) – Single sample to predict

Returns:

Returns prediction for sample

Return type:

any

save(file_name)

Save model to json.

Parameters:

file_name (str) – Target file name.

signal_names = None

Signal / feature names used within the model

abstract summary ()

A summary method for the model

Returns:

Summary text

Return type:

str

abstract train (data)

This is the method to train the model. The data parameter is the dataframe to use. Must be implemented by Model.

Parameters:

data (pandas.DataFrame) – Dataframe to train the model.

Returns:

Does not return. Throw on exception during training.

Return type:

void

proficloud.ml.SomReconstructionError module

class proficloud.ml.SomReconstructionError.SomReconstructionErrorModel

Bases: proficloud.ml.AbstractModel.AbstractModelClass

Self-Organizing Map model with reconstruction error anomaly detection. https://www.sciencedirect.com/science/article/pii/S221282711830307X

static load (file_name)

Load model from json file.

Parameters:

file_name (str) – Source file name.

Returns:

Model instance

Return type:

AbstractModelClass

predict(data, n_jobs=None)

This is the method to predict a whole dataset. The data parameter is the dataframe to use. Must be implemented by Model.

Parameters:

data (pandas.DataFrame) – Dataframe to evaluate

Returns:

Returns list with an entry for each row of the dataframe.

Return type:

list

predict_raw = None

Parameter for prediction. if True reconstruction error is returned. If false, output > 0 marks an anomaly.

predict_sample(sample)

This is the method to predict a single sample. The sample parameter is sample to predict. Must be implemented by Model.

Parameters:

sample (pandas.Series / numpy.array) – Single sample to predict

Returns:

Returns prediction for sample

Return type:

any

save(file_name)

Save model to json.

Parameters:

file_name (str) – Target file name.

scaler = None

Data scaling, created during training. Used to scale data to range [0,1].

signal_names = None

Signal names

som = None

Self-Organizing Map neural network

summary()

A summary method for the model

Returns:

Summary text

Return type:

str

threshold = None

Threshold for anomaly detection. Calculated from training data.

train(data)

This is the method to train the model. The data parameter is the dataframe to use. Must be implemented by Model.

Parameters:

data (pandas.DataFrame) – Dataframe to train the model.

Returns:

Does not return. Throw on exception during training.

Return type:

void

training_epochs = None

Hyperparameter, number of training epochs

training_learning_rate = None

Hyperparameter, Initial learning rate

training_side_length = None

Hyperparameter, side length of SOM (x and y are equal)

proficloud.ml.StateTiming module

class proficloud.ml.StateTiming.AnomalyTypeEnum

Bases: enum.Enum

AnomalyType Enumeration. Enumerates different anomaly types.

NOT_TESTED = -1
NO_ANOMALY = 0
STATE_ANOMALY = 2
TIME_ANOMALY = 1
UNKNOWN_STATE = 3
VALUE_ERROR = 4
class proficloud.ml.StateTiming.SignalThreshold (signal_name, min_value=inf, max_value=0)

Bases: object

Class to store min/max thresholds for signals.

max_value = None

Maximum signal value

min_value = None

Minimum signal value

signal_name = None

Signal name

class proficloud.ml.StateTiming.State (state_id, transitions, signal_thresholds)

Bases: object

Class representing a state.

signal_thresholds = None

Learned min-max thresholds for provided signals

state_id = None

State ID. A unique identifier for each state

transitions = None

Outgoing transitions to other states

class proficloud.ml.StateTiming.StateTimingModel

Bases: proficloud.ml.AbstractModel.AbstractModelClass

StateTimingModel. This learns a state-machine, also called automaton, based on a given state variable and timestamp. This model is a normal behaviour model and detects deviations in state transitions (timing, events) and detects range violations in other provided signals.

accepting_states = None

The accepting states of the automaton/state machine

current_state = None

Current state during prediction

current_time = None

Current relative time during prediction

filter_zero_variance = None

Filter zero-variance signals

initial_state = None

Initial state of the automaton

static load (file_name)

Load model from json file.

Parameters:

file_name (str) – Source file name.

Returns:

Model instance

Return type:

AbstractModelClass

maxTimeOffset = None

Time offset for relative max transition timing (to adjust sensitivity)

maxValueOffsetFactor = None

Offset factor for signal max value (to adjust sensitivity)

minTimeOffset = None

Time offset for relative min transition timing (to adjust sensitivity)

minValueOffsetFactor = None

Offset factor for signal min value (to adjust sensitivity)

predict(data)

This is the method to predict a whole dataset. The data parameter is the dataframe to use. Must be implemented by Model.

Parameters:

data (pandas.DataFrame) – Dataframe to evaluate

Returns:

Returns list with an entry for each row of the dataframe.

Return type:

list

predict_sample(sample)

This is the method to predict a single sample. The sample parameter is sample to predict. Must be implemented by Model.

Parameters:

sample (pandas.Series / numpy.array) – Single sample to predict

Returns:

Returns prediction for sample

Return type:

any

resetPrediction()

Reset prediction and internal automaton state

save(file_name)

Save model to json.

Parameters:

file_name (str) – Target file name.

signal_names = None

The signal names used in this model

start_time = None

Absolute start time of prediction

state_signal_name = None

The state signal name

states = None

The states of the model (Disctionary)

summary()

A summary method for the model

Returns:

Summary text

Return type:

str

timestamp_signal_name = None

Timestamp signal name. Must be unix-like timestamp.

train(data)

This is the method to train the model. The data parameter is the dataframe to use. Must be implemented by Model.

Parameters:

data (pandas.DataFrame) – Dataframe to train the model.

Returns:

Does not return. Throw on exception during training.

Return type:

void

class proficloud.ml.StateTiming.StateTimingModelAnomaly

Bases: object

State timing model anomaly class. Used in predict method

anomaly = None

True on anomaly, False if everything is ok!

anomalytype = None

Type of the anomaly

relative_time = None

relative timing of the anomaly

source_state = None

Source state id of the anomaly

target_state = None

Target state od of the anomaly

timestamp = None

Absolute timestamp of anomaly

transition = None

transition id associated with the anomaly

value_error = None

List of value errors (contains type ValueErrorAnomaly)

class proficloud.ml.StateTiming.Transition (source_state, target_state)

Bases: object

Class representing a transition.

max_time = None

Maximum transition time (relative)

min_time = None

Minimum transition time (relative)

source_state = None

Source state ID

target_state = None

Target state ID

class proficloud.ml.StateTiming.ValueErrorAnomaly (signal_name, signal_value, signal_min_value, signal_max_value)

Bases: object

Value error anomaly. Provides details about signal value range violations.

signal_max_value = None

Signal maximum value

signal_min_value = None

Signal minumum value

signal_name = None

Signal name

signal_value = None

Actual signal value

Module contents