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:
- 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
= NoneSignal / 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
- static
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:
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
= NoneParameter 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
= NoneData scaling, created during training. Used to scale data to range [0,1].
signal_names
= NoneSignal names
som
= NoneSelf-Organizing Map neural network
summary
()A summary method for the model
Returns: Summary text
Return type: str
threshold
= NoneThreshold 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
= NoneHyperparameter, number of training epochs
training_learning_rate
= NoneHyperparameter, Initial learning rate
training_side_length
= NoneHyperparameter, side length of SOM (x and y are equal)
- static
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
= NoneMaximum signal value
min_value
= NoneMinimum signal value
signal_name
= NoneSignal name
- class
proficloud.ml.StateTiming.
State
(state_id, transitions, signal_thresholds) Bases:
object
Class representing a state.
signal_thresholds
= NoneLearned min-max thresholds for provided signals
state_id
= NoneState ID. A unique identifier for each state
transitions
= NoneOutgoing 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
= NoneThe accepting states of the automaton/state machine
current_state
= NoneCurrent state during prediction
current_time
= NoneCurrent relative time during prediction
filter_zero_variance
= NoneFilter zero-variance signals
initial_state
= NoneInitial 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:
maxTimeOffset
= NoneTime offset for relative max transition timing (to adjust sensitivity)
maxValueOffsetFactor
= NoneOffset factor for signal max value (to adjust sensitivity)
minTimeOffset
= NoneTime offset for relative min transition timing (to adjust sensitivity)
minValueOffsetFactor
= NoneOffset 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
= NoneThe signal names used in this model
start_time
= NoneAbsolute start time of prediction
state_signal_name
= NoneThe state signal name
states
= NoneThe states of the model (Disctionary)
summary
()A summary method for the model
Returns: Summary text
Return type: str
timestamp_signal_name
= NoneTimestamp 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
= NoneTrue on anomaly, False if everything is ok!
anomalytype
= NoneType of the anomaly
relative_time
= Nonerelative timing of the anomaly
source_state
= NoneSource state id of the anomaly
target_state
= NoneTarget state od of the anomaly
timestamp
= NoneAbsolute timestamp of anomaly
transition
= Nonetransition id associated with the anomaly
value_error
= NoneList of value errors (contains type ValueErrorAnomaly)
- class
proficloud.ml.StateTiming.
Transition
(source_state, target_state) Bases:
object
Class representing a transition.
max_time
= NoneMaximum transition time (relative)
min_time
= NoneMinimum transition time (relative)
source_state
= NoneSource state ID
target_state
= NoneTarget 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
= NoneSignal maximum value
signal_min_value
= NoneSignal minumum value
signal_name
= NoneSignal name
signal_value
= NoneActual signal value