# Machine Learning Manager Ignition

**URL:** <https://forum.inductiveautomation.com/t/machine-learning-manager-ignition/94785>\
**Category:** Ignition Exchange\
**Created:** [August 19, 2024, 1:19am UTC](https://forum.inductiveautomation.com/t/machine-learning-manager-ignition/94785 "2024-08-19T01:19:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fadillah\_Ariadinata](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@Fadillah\_Ariadinata](https://forum.inductiveautomation.com/u/Fadillah_Ariadinata)\
**Post date:** [August 19, 2024, 1:19am UTC](https://forum.inductiveautomation.com/t/machine-learning-manager-ignition/94785/1 "2024-08-19T01:19:04Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/1/d1f8c17fc2ffce56120bf8e1f1280827ddaffc4a.png)

---

<div class="post-metadata">

**Author:** ![Conner\_Futa](https://avatars.discourse-cdn.com/v4/letter/c/bc8723/32.png) [@Conner\_Futa](https://forum.inductiveautomation.com/u/Conner_Futa)\
**Post date:** [August 21, 2024, 12:00am UTC](https://forum.inductiveautomation.com/t/machine-learning-manager-ignition/94785/2 "2024-08-21T00:00:50Z")

</div>

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.

```python
# 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.
