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_ID | Measurement (mm) |
|---|---|
| 1 | 10.02 |
| 2 | 9.98 |
| 3 | 10.05 |
| 4 | 10.20 |
| 5 | 9.95 |
| 6 | 10.10 |
| 7 | 10.50 |
| 8 | 9.99 |
| 9 | 10.00 |
| 10 | 9.97 |
Step 2: Statistical Process Control Setup
Calculate mean and standard deviation :
For this dataset:
mm
mm (calculated)
Set control limits for the control chart (typically ):
Upper Control Limit (UCL) = mm
Lower Control Limit (LCL) = 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:
pythonimport 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.
sets the upper bound on the fraction of anomalies.
Training fits a boundary enclosing the normal points.
Measurements outside are labeled anomalies ().
Step 5: Output Table — Anomaly Detection Results
| Sample_ID | Measurement (mm) | SPC Status | One-Class SVM Prediction |
|---|---|---|---|
| 1 | 10.02 | Within Control | Normal (1) |
| 2 | 9.98 | Within Control | Normal (1) |
| 3 | 10.05 | Within Control | Normal (1) |
| 4 | 10.20 | Within Control | Normal (1) |
| 5 | 9.95 | Within Control | Normal (1) |
| 6 | 10.10 | Within Control | Normal (1) |
| 7 | 10.50 | Within Control | Anomaly (-1) |
| 8 | 9.99 | Within Control | Normal (1) |
| 9 | 10.00 | Within Control | Normal (1) |
| 10 | 9.97 | Within Control | Normal (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
pythonimport 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()
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.