Machine Learning  

Using ML.NET for Predictive Maintenance in Web Dashboards

Predictive maintenance has become a critical capability for modern digital platforms, especially in manufacturing, logistics, energy, and large-scale asset management. Instead of waiting for equipment failure, machine learning models analyse historical data patterns and anticipate issues before they occur.

Using ML.NET, developers can build machine-learning models directly inside a .NET ecosystem without relying on external Python services. When integrated with ASP.NET Core APIs and Angular dashboards, organisations can get real-time insights and early warnings about potential failures.

This article explains how to design, build, train, deploy and visualise a predictive maintenance system using ML.NET + ASP.NET Core + SQL Server + Angular, tailored for beginners to advanced developers.

Introduction to Predictive Maintenance

Predictive maintenance uses machine learning to forecast when equipment is likely to fail. Instead of time-based servicing (scheduled maintenance), predictive maintenance looks at patterns such as:

  • Temperature fluctuations

  • Vibration frequency

  • Pressure variances

  • Electrical load

  • Operating hours

  • Sensor anomalies

ML.NET allows you to train models like:

  • Regression (predict time-to-failure)

  • Classification (predict “Likely to fail” vs “Healthy”)

  • Anomaly detection (detect sudden unusual behaviour)

Predictive Maintenance Workflow (Smaller Header)

Sensor Data → Data Storage → Feature Engineering → ML.NET Model Training 
     ↓             ↓                    ↓               ↓
 Real-Time Monitoring ← ASP.NET Core APIs ← ML.NET Model Scoring ← Angular Web Dashboard

Flowchart (Smaller Header)

+-----------------------+
| Collect Sensor Data   |
+----------+------------+
           |
           v
+----------+------------+
| Store in SQL Server   |
+----------+------------+
           |
           v
+----------+------------+
| Train ML.NET Model    |
+----------+------------+
           |
           v
+----------+------------+
| Deploy Model in API   |
+----------+------------+
           |
           v
+----------+------------+
| Predict in Real Time  |
+----------+------------+
           |
           v
+------------------------+
| Show Alerts in Angular |
+------------------------+

Architecture Diagram (Visio-Style, Smaller Header)

      +------------------------+
      |    Angular Dashboard   |
      | Charts, Alerts, UI     |
      +-----------+------------+
                  |
                  v
      +-----------+------------+
      |   ASP.NET Core API     |
      | Prediction Controller   |
      +-----------+------------+
                  |
                  v
      +-----------+------------+
      |   ML.NET Model         |
      | Trained Model Files    |
      +-----------+------------+
                  |
     +------------+-------------+
     |    SQL Server Database   |
     | SensorLogs, Predictions  |
     +---------------------------+

ER Diagram (Smaller Header)

+---------------------------+
| Machines                  |
+---------------------------+
| MachineId (PK)            |
| Name                      |
| Location                  |
| LastServiceDate           |
+---------------------------+
             |
             | 1 ---> *
             |
+---------------------------+
| SensorLogs                |
+---------------------------+
| LogId (PK)                |
| MachineId (FK)            |
| Temperature               |
| Pressure                  |
| Vibration                 |
| Voltage                   |
| LoggedOn                  |
+---------------------------+
             |
             | 1 ---> *
             |
+---------------------------+
| Predictions               |
+---------------------------+
| PredictionId (PK)         |
| MachineId (FK)            |
| FailureProbability        |
| Score                     |
| PredictedOn               |
+---------------------------+

Sequence Diagram (Smaller Header)

User → Angular: Open Dashboard
Angular → API: GET /status
API → SQL Server: Fetch latest sensor logs
SQL Server → API: Return logs
API → ML.NET Model: Predict failure probability
ML.NET Model → API: Prediction result
API → Angular: Return status with predictions
Angular → User: Show health indicators & alerts

Building the ML.NET Model

ML.NET provides two major approaches:

  1. Model Builder (UI-based)

  2. Code-first ML pipeline

We will use the code-first approach for full automation.

Step 1: Define Input and Output Schemas

public class SensorData
{
    public float Temperature { get; set; }
    public float Pressure { get; set; }
    public float Vibration { get; set; }
    public float Voltage { get; set; }
}

public class FailurePrediction
{
    public bool PredictedLabel { get; set; }  // Failure or No Failure
    public float Probability { get; set; }
    public float Score { get; set; }
}

Step 2: Create the ML Pipeline

var context = new MLContext();

var dataView = context.Data.LoadFromTextFile<SensorData>(
    "sensor-data.csv", hasHeader: true, separatorChar: ',');

var pipeline =
    context.Transforms.Concatenate("Features",
        nameof(SensorData.Temperature),
        nameof(SensorData.Pressure),
        nameof(SensorData.Vibration),
        nameof(SensorData.Voltage))
    .Append(context.BinaryClassification.Trainers.FastTree());

Step 3: Train the Model

var model = pipeline.Fit(dataView);
context.Model.Save(model, dataView.Schema, "model.zip");

Integrating ML.NET Model in ASP.NET Core

Service to Load and Predict

public class PredictionService
{
    private readonly PredictionEngine<SensorData, FailurePrediction> _engine;

    public PredictionService()
    {
        var ctx = new MLContext();
        var model = ctx.Model.Load("model.zip", out _);
        _engine = ctx.Model.CreatePredictionEngine<SensorData, FailurePrediction>(model);
    }

    public FailurePrediction Predict(SensorData input)
    {
        return _engine.Predict(input);
    }
}

API Controller for Predictions

[ApiController]
[Route("api/predict")]
public class PredictController : ControllerBase
{
    private readonly PredictionService _service;

    public PredictController(PredictionService service)
    {
        _service = service;
    }

    [HttpPost]
    public IActionResult Predict([FromBody] SensorData data)
    {
        var result = _service.Predict(data);
        return Ok(result);
    }
}

Angular Dashboard for Monitoring

Fetch predictions

this.http.post('/api/predict', sensorData)
  .subscribe(res => {
    this.prediction = res;
  });

Display indicators (example)

<div *ngIf="prediction.probability > 0.7" class="alert alert-danger">
  High failure risk detected
</div>

Operational Best Practices

  • Use scheduling jobs to retrain the model weekly/monthly

  • Monitor data drift in sensor patterns

  • Store each prediction for audit and trend analysis

  • Use background services for continuous scoring

  • Implement real-time WebSocket updates for dashboards

  • Optimise API performance using pooled PredictionEngines

  • Use SQL Server time-series tables for large volumes

Advanced Capabilities

  • Anomaly detection using ML.NET RandomizedPcaTrainer

  • Time series forecasting using SSAForecasting for predicting future states

  • Hybrid scoring (model + rules) for production safety

  • Edge deployment (offline factory environments)

  • AI explanations (feature contributions)

Conclusion

Predictive maintenance using ML.NET helps organisations detect problems before they occur, reducing downtime and operational costs.

With ASP.NET Core handling predictions, SQL Server storing historical data, and Angular presenting real-time dashboards, the system becomes scalable, maintainable, and suitable for industrial use.