Step-by-Step Case Study: Product Quality Monitoring in Engineering Using SPC and One-Class SVM in Python

Product quality monitoring is a crucial engineering task to ensure consistent manufacturing standards and reduce defects. This case study demonstrates how Statistical Process Control (SPC) combined with supervised anomaly detection using One-Class Support Vector Machines (SVM) in Python enables real-time quality assurance (QA) and defect reduction.

Understanding the Problem

Manufacturers must monitor product quality metrics continuously to detect deviations and anomalies early. SPC uses control charts to track variations over time, while One-Class SVM identifies outliers that signal defects or process shifts.

Step 1: Defining Objectives and Data Collection

The goal is real-time detection of anomalies in product quality metrics (e.g., dimensions, weight) to reduce defect rates and improve QA processes.

Sample Dataset (Measurements of a Critical Dimension)

Sample_IDMeasurement (mm)
110.02
29.98
310.05
410.20
59.95
610.10
710.50
89.99
910.00
109.97

Step 2: Statistical Process Control Setup

Calculate mean xˉ and standard deviation s:

xˉ=1ni=1nxi,s=1n1i=1n(xixˉ)2

For this dataset:

  • xˉ=10.02+9.98++9.9710=10.076 mm

  • s=0.178 mm (calculated)

Set control limits for the control chart (typically ±3s):

  • Upper Control Limit (UCL) = xˉ+3s=10.61 mm

  • Lower Control Limit (LCL) = xˉ3s=9.54 mm

Samples outside this range may indicate defects or process issues.

Step 3: Applying One-Class SVM for Anomaly Detection

One-Class SVM models the normal data distribution and detects anomalous measurements (defects).

Python implementation:

python
import numpy as np from sklearn.svm import OneClassSVM measurements = np.array([10.02, 9.98, 10.05, 10.20, 9.95, 10.10, 10.50, 9.99, 10.00, 9.97]).reshape(-1, 1) oc_svm = OneClassSVM(kernel='rbf', gamma='auto', nu=0.1) oc_svm.fit(measurements) predictions = oc_svm.predict(measurements) # 1 = normal, -1 = anomaly print(predictions)

Step 4: Step-by-Step Calculation Example

  • The One-Class SVM uses a kernel (radial basis function) to map measurements into high-dimensional space.

  • ν=0.1 sets the upper bound on the fraction of anomalies.

  • Training fits a boundary enclosing the normal points.

  • Measurements outside are labeled anomalies (1).

Step 5: Output Table — Anomaly Detection Results

Sample_IDMeasurement (mm)SPC StatusOne-Class SVM Prediction
110.02Within ControlNormal (1)
29.98Within ControlNormal (1)
310.05Within ControlNormal (1)
410.20Within ControlNormal (1)
59.95Within ControlNormal (1)
610.10Within ControlNormal (1)
710.50Within ControlAnomaly (-1)
89.99Within ControlNormal (1)
910.00Within ControlNormal (1)
109.97Within ControlNormal (1)

Sample 7 is detected as an anomaly by One-Class SVM, signaling potential defect despite being within 3-sigma control limits.

Step 6: Visualization — SPC Control Chart with Anomalies

python
import matplotlib.pyplot as plt plt.plot(range(1, 11), measurements, marker='o', color='blue', label='Measurements') plt.axhline(y=10.61, color='red', linestyle='--', label='UCL') plt.axhline(y=9.54, color='red', linestyle='--', label='LCL') plt.axhline(y=10.076, color='green', linestyle='-', label='Mean') # Highlight anomaly plt.scatter(7, 10.50, color='orange', s=100, label='Anomaly (One-Class SVM)') plt.title('SPC Control Chart with One-Class SVM Anomaly') plt.xlabel('Sample ID') plt.ylabel('Measurement (mm)') plt.legend() plt.show()
Interpretation:

  • Run this code in python to visualize. The chart shows measurements tracked with mean and control limits.

  • One-Class SVM highlights Sample 7 as an anomaly, suggesting the process may require inspection even if statistical limits are not violated.

Conclusion

Combining SPC with One-Class SVM enables real-time quality monitoring with greater sensitivity to subtle defects. Python’s ecosystem facilitates implementation of this hybrid predictive quality assurance, resulting in faster defect detection and reduced manufacturing errors.

Adopting such techniques in engineering improves product consistency, lowers waste, and enhances customer satisfaction.