Deploy deterministic machine learning models for industrial automation with ML.NET integration
The AI ML Integration Connector brings deterministic machine learning capabilities to FrameworX solutions through ML.NET, Microsoft's cross-platform machine learning framework. Unlike probabilistic LLMs, this connector provides consistent, repeatable results suitable for real-time industrial control and monitoring applications.
Industrial Data → FrameworX Tags → ML Models → Predictions
↓ ↑
[Historian] [ML.NET Engine]
↓ ↑
[Training] [Inference]
| Property | Value |
|---|---|
| Name | ML.NET Integration |
| Framework | ML.NET 3.0+ |
| Runtime | .NET 8.0 |
| Model Types | Classification, Regression, Anomaly Detection, Time-Series |
| Configuration | Scripts → Classes |
| Execution | Real-time & Batch |
Note: The built-in AnomalyML Library class uses the SR-CNN algorithm. Other algorithms are available through custom ML.NET pipelines built in Visual Studio.
FrameworX supports three ML integration patterns. Choose the one that fits your use case:
| Pattern | Best For | ML Expertise Needed | Page |
|---|---|---|---|
| AnomalyML Library Class | Real-time anomaly detection on live sensor data. Auto-trains from incoming data — no Visual Studio required. | None | [Skill Edge ML Pipeline](Skill Edge ML Pipeline) / [ML.NET Tutorial](ML.NET Tutorial) |
| Pre-trained Models (.zip) | Multi-variable regression, classification, or anomaly detection using models trained offline in Visual Studio. | Intermediate | [ML.NET Pre-trained Models Example](ML.NET Example) |
| Model Builder (VS Extension) | Visual Studio Model Builder extension generates ML code and trained models automatically from a dataset. | Beginner-Intermediate | [ML.NET Model Builder Example](ML.NET Model Builder Example) |
Starting out? Use the AnomalyML Library Class. Import it in one click, wire it to your sensor tags, and anomaly detection starts working automatically after ~100 data points.
Create specialized script classes that implement ML.NET models for real-time inference and training.
Learn more: [Scripts Classes Reference](Scripts Classes Reference)
FrameworX's event-driven architecture and consistent namespace provide the foundation for ML integration. The Unified Namespace, expression engine, and historian work together to feed sensor data into ML models and deliver predictions back to alarms and displays.
Learn more: [AI-Ready by Design](AI-Ready by Design)
Pre-built examples demonstrate ML integration for industrial scenarios.
Learn more: [BottlingLine ML Demo](BottlingLine ML Demo)
The AnomalyML class is self-contained pure .NET with no tag references. After import, the only customization needed is the sensitivity parameters at the top of the class:
// SENSITIVITY: SR-CNN detection parameters
// Adjust these after importing into your application.
// windowSize: detection window (higher = less sensitive, more stable)
// threshold: anomaly threshold (lower = more sensitive, more false positives)
// trainingBufferSize: data points to collect before model trains
// At 5-second scan rate: 100 points = ~8 minutes warmup
// Defaults work well for most industrial processes at 1-5 second scan rates.
private int _windowSize = 32;
private double _threshold = 0.15;
private int _trainingBufferSize = 100;
AnomalyML Public Methods:
| Method | Returns | Description |
|---|---|---|
Check(double) | double | Feed sensor value, returns anomaly score. Must execute first each cycle. |
GetIsAnomaly() | bool | True if last Check() detected an anomaly |
GetScore() | double | Anomaly severity from last Check() (0.0 = normal, 1.0 = severe) |
GetBaseline() | double | Expected normal value from last Check() |
IsModelReady() | bool | True after auto-training completes (~100 data points) |
GetAnomalies() | string | Recent anomaly history (also exposed as MCP Tool for AI queries) |
Before wiring expressions, create tags to receive the model's predictions:
| Tag Name | Type | Description |
|---|---|---|
{Area}/ML/Score | Analog | Anomaly score (0.0 to 1.0) |
{Area}/ML/IsAnomaly | Digital | True when anomaly detected |
{Area}/ML/Baseline | Analog | Expected normal value |
{Area}/ML/ModelReady | Digital | True after training completes |
Where {Area} is your UNS folder path (e.g., Brewery/BrewHouse, Plant/Reactor1).
Create expressions in Scripts → Expressions to wire the ML class to your tags:
| ObjectName | Expression | Trigger |
|---|---|---|
Tag.{Area}/ML/Score | Script.Class.AnomalyML.Check(Tag.{Area}/{SensorTag}) | OnChange |
Tag.{Area}/ML/IsAnomaly | Script.Class.AnomalyML.GetIsAnomaly() | OnChange |
Tag.{Area}/ML/Baseline | Script.Class.AnomalyML.GetBaseline() | OnChange |
Tag.{Area}/ML/ModelReady | Script.Class.AnomalyML.IsModelReady() | OnChange |
All four expressions should use the same TriggerTag (your sensor tag). The Score expression must execute first each cycle — it calls Check() which runs the ML model. The other three read results from that same prediction.
Important: After starting the runtime, the model needs ~100 data points to train. During warmup, Score will be 0 and ModelReady will be false. At a 5-second scan rate, expect ~8 minutes before predictions begin.
Multiple sensors: Each sensor needs its own class instance (e.g.,
AnomalyML_Temp,AnomalyML_Press) since one instance tracks one data stream. Import the Library class multiple times with different names.
For the complete step-by-step pipeline including alarms and displays, see the [Skill Edge ML Pipeline](Skill Edge ML Pipeline).
Monitor streaming sensor data for deviations using the AnomalyML Library class.
Tutorial: [How to Build an ML Model](ML.NET Tutorial)
The configuration workflow above (Steps A–C) is the complete setup for real-time anomaly detection. After wiring the expressions, create a Digital alarm on the IsAnomaly tag to notify operators when anomalies are detected:
Tag.{Area}/ML/IsAnomalyIsAnomaly = true)Forecast equipment failures using historical patterns. This pattern uses pre-trained models built in Visual Studio with multi-variable input features:
// Example: Pre-trained regression model loaded from .zip file
// See ML.NET Pre-trained Models Example for working implementation
public class MaintenanceML
{
private PredictionEngine<EquipmentFeatures, FailurePrediction> engine;
public void LoadModel(string modelPath)
{
var mlContext = new MLContext();
var model = mlContext.Model.Load(modelPath, out var schema);
engine = mlContext.Model.CreatePredictionEngine<EquipmentFeatures, FailurePrediction>(model);
}
public double PredictHoursToFailure(double temperature, double vibration, double runtime)
{
var features = new EquipmentFeatures
{
Temperature = (float)temperature,
Vibration = (float)vibration,
RuntimeHours = (float)runtime
};
return engine.Predict(features).HoursToFailure;
}
}
Note: This pattern requires building and training a model externally in Visual Studio. See [ML.NET Pre-trained Models Example](ML.NET Example) for a working implementation.
Anticipate product quality based on process parameters. Like Predictive Maintenance, this uses pre-trained classification models:
// Example: Pre-trained classification model
// See ML.NET Pre-trained Models Example for working implementation
public class QualityML
{
private PredictionEngine<ProcessFeatures, QualityPrediction> engine;
public string PredictGrade(double temperature, double pressure, double speed)
{
var features = new ProcessFeatures
{
Temperature = (float)temperature,
Pressure = (float)pressure,
LineSpeed = (float)speed
};
return engine.Predict(features).QualityGrade; // A, B, C, etc.
}
}
Note: This is an illustrative pattern. See [ML.NET Pre-trained Models Example](ML.NET Example) for a working multi-model implementation with Regression, Classification, and Anomaly Detection.
A comprehensive example demonstrating ML integration in a bottling plant:
[BottlingLine ML Demo](BottlingLine ML Demo) — Complete IoT solution with:
Build your first ML model for anomaly detection:
[How to Build an ML Model](ML.NET Tutorial) — Step-by-step guide covering:
// Cache models in memory (pre-trained model pattern)
private static readonly Dictionary<string, ITransformer> ModelCache = new();
public ITransformer GetModel(string name)
{
if (!ModelCache.TryGetValue(name, out var model))
{
model = mlContext.Model.Load($"Models/{name}.zip", out _);
ModelCache[name] = model;
}
return model;
}
// Batch predictions when possible (pre-trained model pattern)
public double[] BatchPredict(double[][] featureSets)
{
return model.Transform(featureSets).GetColumn<double>("Score");
}
Note: The AnomalyML Library class handles its own model caching internally. These patterns apply to custom pre-trained model implementations.
public string SafePredict(double value)
{
try
{
if (double.IsNaN(value) || double.IsInfinity(value))
return "Invalid Input";
var prediction = model.Predict(value);
@Info.Trace($"ML Prediction: {prediction}");
return prediction.ToString();
}
catch (Exception ex)
{
@Alarm.Create("ML_Error", ex.Message);
return "Prediction Error";
}
}
Track and manage multiple model versions (pre-trained model pattern):
public class ModelManager
{
private readonly MLContext mlContext = new();
public ITransformer LoadModel(string version)
{
var path = $"Models/model_v{version}.zip";
return mlContext.Model.Load(path, out var schema);
}
}
Combine multiple models for improved accuracy (advanced custom pattern):
public double EnsemblePredict(double value)
{
var predictions = new[]
{
anomalyModel.Predict(value),
spikeModel.Predict(value),
changePointModel.Predict(value)
};
// Voting or averaging strategy
return predictions.Average();
}
Note: Ensemble methods require building custom ML pipelines in Visual Studio. This is an advanced pattern not covered by the AnomalyML Library class.
Create domain-specific ML workflows using the ML.NET API directly in Script Classes:
public ITransformer BuildCustomPipeline(IDataView trainingData)
{
var mlContext = new MLContext();
return mlContext.Transforms
.NormalizeMinMax("Temperature")
.Append(mlContext.Regression.Trainers.Sdca())
.Fit(trainingData);
}
Note: Custom pipelines give full control over the ML.NET API but require ML expertise. For most anomaly detection use cases, the AnomalyML Library class is the recommended starting point.
Model not loading (pre-trained models)
.zip file path is correct and accessible at runtimeAnomalyML not detecting anomalies
ModelReady tag is true — if false, the model is still training (needs ~100 data points)_threshold (lower = more sensitive) or _windowSize (lower = more reactive)Poor prediction accuracy
Performance issues
Integration errors
| Aspect | ML.NET Integration | AI Runtime (LLM) |
|---|---|---|
| Output Type | Deterministic | Probabilistic |
| Use Case | Control & Monitoring | Assistance & Analysis |
| Response Time | Microseconds | Seconds |
| Training | Required (auto or manual) | Pre-trained |
| Consistency | 100% Repeatable | Variable |
| Suitable for Control | Yes | No |
| Runs Offline | Yes | Requires cloud/API |
Both approaches complement each other. Use ML.NET for real-time control loops and alarms. Use AI Runtime for operator assistance, natural language queries, and solution analysis. See [AI Integration](AI Integration) for the full AI feature overview.
The AI ML Integration Connector provides industrial-grade machine learning capabilities that maintain the determinism and reliability required for automation systems, while enabling advanced analytics and predictive capabilities that improve operational efficiency.