Machine Learning Manager Ignition

I am currently working on a project for a machine learning manager exchange. In its configuration, it's necessary to specify a time range for the data retrieved from the tag. I’m curious if it’s possible to configure the machine learning model to run with real-time data from the tag, meaning it updates continuously.

It's currently not possible to configure a model to do this through the UI, but this example script should have the same effect by retraining/updating the model. I would recommend adding either a gateway timer or scheduled script to the MachineLearningManager resource set to run at whatever interval you want to update the model.

# Import
from exchange.ml.hook import (
	tagHistory
	, models
)

# Get the current time as the end date
endDate = system.date.now()

# Get the tag history data
trainingData = tagHistory.getTagHistory(
	paths = ['Tag1', 'Tag2']
	, startDate = system.date.addHours(endDate, -4)
	, endDate = endDate
	, returnSize = 300
	, aggMode = 'Average'
	, noInterpolation = True
	, ignoreBadQuality = False
)

# Update the model
models.update(
	modelID = 1
	, name = 'Model'
	, description = 'Model Description'
	, model_type = 'regression' 
	, algorithm = 'OLSMultLinearRegression'
	, args = [0] 
	, trainingData = trainingData
)

It's also worth noting that using a continuously trained model can have some unintended consequences. Where if the process that the model is being trained for starts to drift in a negative direction the model might not catch certain issues now that the process drift is included in the model's training data.

2 Likes