Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

ML.NET Script Class — Machine Learning in FrameworX Scripts

Create machine learning models that run inside FrameworX using Script Classes with ML.NET. The AI writes the C# code, connects it to live tags, creates output tags for predictions, and configures model persistence — all within the FrameworX scripting engine.

...

Architecture

No Format
Input Tags ???-> Script Class (ML.NET) ???-> Output Tags
   ?|              ?|                         ?|
 Live data    Train / Predict           Predictions, scores,
 from UNS     Model persisted to        anomaly flags, forecasts
              solution folder            ??? Alarms / Dashboard

When to Use This Skill

...

  • Solution open with input tags already created (the tags the model will read from)
  • Tags should have live or simulated data flowing (Value Simulator or real device)
  • If starting from scratch, apply the New Solution skill first to create tags and a data source

MCP Tools and Tables

Category

Items

Tools

get_table_schema, write_objects, get_objects, list_elements, search_docs

Tables

UnsTags, ScriptsClasses, ScriptsExpressions, ScriptsTasks

...

Step 0: Identify the ML Task

...

Goal-to-algorithm mapping (use as suggestions only — always confirm with user)

User Goal

Suggested Algorithm

Predictive maintenance — single sensor

Anomaly Detection (Spike)

Predictive maintenance — multiple sensors

Binary Classification

Detect sensor failures / outliers

Anomaly Detection (Spike)

Detect gradual drift or process shift

Anomaly Detection (ChangePoint)

Predict future values

Time-Series Forecasting (SSA)

Energy / consumption modeling

Regression

Quality control pass/fail

Binary Classification

Fault prediction yes/no

Binary Classification

Production / demand forecasting

Time-Series Forecasting (SSA)

Process output from multiple inputs

Regression

Required information before proceeding

Information

Why

Input tag path(s)

The model reads from these tags

ML algorithm

Determines the ML.NET pipeline to generate

Output semantics

What the predictions mean (anomaly score, forecast value, etc.)

...

Step 1: Create Output Tags

...

  1. ?? Confirm the solution is set to Multiplatform before starting the runtime. ML.NET requires .NET 8+ — if the solution was created as Windows (.NET 4.8), training will fail with a System.Math / CpuMath error. Instruct the user:

    "Before starting the runtime, please confirm your solution is set to Multiplatform: Solution → Settings → Target Platform = Multiplatform, then Product → Modify."

    Only proceed if the user confirms this is already set.
  2. Do NOT start the runtime automatically. Inform the user that all scripts are configured and that they can start the runtime whenever ready. Only call designer_action('start_runtime') if the user explicitly requests it.
  3. Wait for training — the model needs MinTrainingSize data points before predictions begin
  4. Check output tags — verify LastPrediction timestamp is updating
  5. Screenshot — if a dashboard exists, take a screenshot to confirm predictions are flowing

...

Common Pitfalls

Mistake

Why It Happens

How to Avoid

Missing ML.NET namespaces

Used AddMLNetNamespaces: true (field does not exist — silently ignored) or omitted NamespaceDeclarations entirely

Always set NamespaceDeclarations: "Microsoft.ML;Microsoft.ML.Data;..." in write_objects. AddMLNetNamespaces is not a valid field.

CS0234 error in ScriptsTasks

Called Script.Class.<Name>.Predict(...) without @ prefix

Always use @Script.Class.<Name>.Predict(...) inside ScriptsTasks — the @ prefix is required for all runtime object references.

Tag reference without @Tag.

Confusing with Expression syntax

Always @Tag.Path/Name.Value inside Script Classes

Model lost on restart

SaveModel or LoadModel not wired up

Always include SaveModel() after TrainModel() and wire LoadModel() in ServerStartup

Training on every call

No guard for already-trained model

Use modelTrained boolean flag

Wrong data types

ML.NET expects float, tags are double

Cast with (float) when feeding ML.NET, cast back to double when writing tags

Expression ObjectName missing Tag. prefix

Confusing tag path vs expression binding

Expression ObjectName needs Tag. prefix; the UNS tag itself does not

Non-empty ObjectName on void ML Predict() call

Expression tries to assign void return to a tag

Leave ObjectName empty when the ML class writes to output tags internally inside RunPrediction()

Used TriggerTag field in Expression

Field does not exist — silently ignored, expression never fires

Use Trigger field with the tag path (no Tag. prefix)

Class is document object

Partial write replaces entire class

Always read-modify-write for existing classes

CS0029 bool-to-int on Digital tag write

Digital tags are backed by int, not bool — assigning a C# bool expression causes a type error

Never assign a raw bool to a Digital tag. Use a ternary: @Tag.Path/ML/Flag.Value = (condition) ? 1 : 0; — never = boolVar; or = (bool expression);

CS0246 Script Class not found in Tasks

Tasks and Classes compile in the same pass; if the Class isn't ordered first, Tasks that reference it fail

Set BuildOrder: "1" on every ML Script Class. Tasks that call it do not need an explicit BuildOrder — they default to a later pass.

Could not load type 'System.Math' from assembly 'System.Runtime' at training time

Solution is targeting .NET 4.8 (Windows platform) — ML.NET CpuMath trainers (FastTree, SSA) are incompatible with .NET 4.8

Go to Solution → Settings → Target Platform → Multiplatform, then Product → Modify to rebuild. This is required for all ML.NET solutions.

Decision Guide

Scenario

ML Task

Trigger

Notes

Single sensor, detect outliers/spikes

Anomaly Detection (Spike)

Expression OnChange

Fast, one tag in / flags out

Single sensor, detect gradual drift

Anomaly Detection (ChangePoint)

Expression OnChange

AI picks this variant when user mentions "drift" or "regime change"

Single sensor, predict future values

Forecasting (SSA)

Expression OnChange or Periodic

Outputs forecast + confidence bounds

Multiple sensors → one continuous value

Regression

Task Periodic

Energy prediction, process modeling

Multiple sensors → yes/no

Binary Classification

Task Periodic

Fault prediction, quality pass/fail

User says "predictive maintenance" + single sensor

Anomaly Detection

Expression OnChange

Most common PdM entry point

User says "predictive maintenance" + multiple sensors

Binary Classification

Task Periodic

Predicts failure from combined inputs

User says "quality control"

Binary Classification

Task Periodic

Pass/fail prediction

User says "forecast" or "predict demand"

Forecasting (SSA)

Expression OnChange or Periodic

Time-series based

User says "you decide" + single sensor

Anomaly Detection

Expression OnChange

Safest default for monitoring

User says "you decide" + multiple sensors

Regression

Task Periodic

Most general multi-input approach