?>Array ( [id] => 99 ) Edge Case: Sensor Reading Classification with Fuzz Factor - WeAreCAS
sessionProp addFormat

Edge Case: Sensor Reading Classification with Fuzz Factor

Scénario de test & Cas d'usage

Contexte Métier

In a manufacturing setting, IoT sensors monitor machine operating temperatures. Due to minor sensor inaccuracies, readings can be very close to a threshold. We need to classify temperatures into 'Normal', 'Warning', and 'Critical' states, ensuring that values just over a boundary are correctly categorized using a tolerance factor (fuzz).
Préparation des Données

Creation of a dataset with sensor temperature readings, including values that are exactly on, or slightly outside of, the defined range boundaries.

Copié !
1DATA casuser.SensorReadings;
2 INFILE DATALINES;
3 INPUT SensorID $ Temperature;
4 DATALINES;
5S01 75.0
6S02 90.0
7S03 90.001
8S04 110.0
9S05 110.05
10S06 .
11;
12RUN;

Étapes de réalisation

1
Create a format library named 'SensorFormats'.
Copié !
1PROC CAS;
2 ACTION sessionProp.addFmtLib /
3 fmtLibName='SensorFormats',
4 replace=true;
5RUN;
6QUIT;
2
Define a numeric format 'TempState' with a 'fuzz' factor of 0.1. This means values within 0.1 of a range's end will be included in that range.
Copié !
1PROC CAS;
2 ACTION sessionProp.addFormat /
3 fmtLibName='SensorFormats'
4 fmtName='TempState'
5 fuzz=0.1
6 ranges={'low-90=Normal', '90<-110=Warning', '110<-high=Critical'};
7RUN;
8QUIT;
3
Apply the 'TempState' format and fetch the results to check how the fuzz factor affects categorization.
Copié !
1PROC casutil;
2 load DATA=casuser.SensorReadings outcaslib='casuser' casout='SensorReadings' replace;
3QUIT;
4PROC CAS;
5 TABLE.fetch /
6 TABLE='SensorReadings',
7 FORMAT=true,
8 vars={'SensorID', 'Temperature'},
9 formatDef={name='Temperature', FORMAT='TempState'};
10RUN;
11QUIT;

Résultat Attendu


The fetched table should show the formatted 'Temperature' values. Sensor S02 (90.0) should be 'Normal'. Sensor S03 (90.001), which is just above 90, should be categorized as 'Warning' due to the fuzz factor. Sensor S05 (110.05) should be 'Critical'. The missing value for S06 should remain unformatted. This validates that the fuzz parameter correctly handles boundary conditions.