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 |
Create specialized script classes that implement ML.NET models for real-time inference and training.
Learn more: Scripts Classes Reference
FrameworX's event-driven architecture and consistent namespace provide the foundation for ML integration.
Learn more: AI-Ready by Design
Pre-built examples demonstrate ML integration for industrial scenarios.
Learn more: BottlingLine ML Demo
csharp
public class AnomalyML
{
private SSAChangePointDetector detector;
private Queue<double> dataBuffer = new Queue<double>(100);
public string Check(double value)
{
dataBuffer.Enqueue(value);
// Detect anomalies using SSA algorithm
var prediction = detector.Predict(value);
if (prediction.IsAnomaly)
{
@Info.Trace($"Anomaly detected: {value}");
@Tag.AnomalyBuffer[0] = $"Alert: {value:F2}";
}
return prediction.Score.ToString();
}
}
Create expressions to trigger ML inference on tag changes:
ObjectName | Expression | Execution |
---|---|---|
Script.Class.AnomalyML.Check(Tag.Pressure) | OnChange | |
Script.Class.QualityML.Predict(Tag.Temperature) | OnChange |
csharp
// Training method in ML Script Class
public void TrainModel()
{
// Get historical data
var data = @Historian.GetValues("Temperature", 10000);
// Create ML pipeline
var pipeline = mlContext.AnomalyDetection
.DetectSpikeBySsa(
outputColumnName: "Prediction",
inputColumnName: "Value",
confidence: 95,
pvalueHistoryLength: 100,
trainingWindowSize: 500,
seasonalityWindowSize: 50);
// Train model
var model = pipeline.Fit(data);
// Save trained model
mlContext.Model.Save(model, dataSchema, "anomaly_model.zip");
}
Monitor streaming sensor data for deviations:
Tutorial: How to Build an ML Model
csharp
[OnTagChange("Tag.Pressure")]
public void MonitorPressure(double value)
{
var result = Script.Class.AnomalyML.Check(value);
if (result.IsAnomaly)
{
@Alarm.Create("PressureAnomaly", value);
}
}
Forecast equipment failures using historical patterns:
csharp
public double PredictTimeToFailure(string equipmentId)
{
var features = new EquipmentFeatures
{
Temperature = @Tag[$"{equipmentId}_Temp"],
Vibration = @Tag[$"{equipmentId}_Vib"],
Runtime = @Tag[$"{equipmentId}_Hours"]
};
return maintenanceModel.Predict(features).HoursToFailure;
}
Anticipate product quality from process parameters:
csharp
public string PredictQuality(ProcessParameters parameters)
{
var prediction = qualityModel.Predict(parameters);
return prediction.QualityGrade; // A, B, C, etc.
}
A comprehensive example demonstrating ML integration in a bottling plant:
BottlingLine ML Demo - Complete IoT solution with:
Build your first ML model for anomaly detection:
How to Build an ML Model - Step-by-step guide covering:
csharp
// Cache models in memory
private static readonly Dictionary<string, ITransformer> ModelCache = new();
// Use async processing for non-critical predictions
public async Task<double> PredictAsync(double[] features)
{
return await Task.Run(() => model.Predict(features));
}
// Batch predictions when possible
public double[] BatchPredict(double[][] featureSets)
{
return model.Transform(featureSets).GetColumn<double>("Score");
}
csharp
public string SafePredict(double value)
{
try
{
if (!IsValidInput(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:
csharp
public class ModelManager
{
public void LoadModel(string version)
{
var path = $"Models/model_v{version}.zip";
currentModel = mlContext.Model.Load(path, out var schema);
}
public void CompareModels(string v1, string v2)
{
// A/B testing between model versions
}
}
Combine multiple models for improved accuracy:
csharp
public double EnsemblePredict(double value)
{
var predictions = new[]
{
anomalyModel.Predict(value),
spikeModel.Predict(value),
changePointModel.Predict(value)
};
// Voting or averaging strategy
return predictions.Average();
}
Create domain-specific ML workflows:
csharp
public ITransformer BuildCustomPipeline()
{
return mlContext.Transforms
.NormalizeMinMax("Temperature")
.Append(mlContext.Transforms.CalculateFeatures())
.Append(mlContext.Regression.Trainers.Sdca())
.Fit(trainingData);
}
Model not loading
Poor prediction accuracy
Performance issues
Integration errors
Aspect | ML.NET Integration | MCP Tools |
---|---|---|
Output Type | Deterministic | Probabilistic |
Use Case | Control & Monitoring | Assistance & Analysis |
Response Time | Microseconds | Seconds |
Training | Required | Pre-trained |
Consistency | 100% Repeatable | Variable |
Suitable for Control | Yes | No |
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.