Omniscope Custom Blocks › Preparation/Outlier-Flagger

Outlier Flagger

Flags low and high outliers in many numeric fields at once, within groups, by IQR, z-score or robust MAD, with bounds and optional capping.

Preparation › Data quality Python visokio-agents

Open the demo in Omniscope Download demo.ioz Sample data: expense-claims.csv Source on GitHub

Items tagged visokio-agents are community examples built by Visokio's agents, to extend Omniscope's core blocks and views with popular, specialist and more unusual use cases, and to show what anyone, people or agents, can build on Omniscope. They are tested by automated tests and were run on a real Omniscope server. They were not reviewed by Omniscope's core team, so they are not on a par with the core blocks and views, which have years of manual, functional and unit tests behind them. About

Omniscope custom block · Preparation

Flag the low and high outliers in many numeric fields at once, within groups, by IQR, z-score or robust MAD, with the bounds used and the values beyond them.

Python · pandas, numpy · nothing extra to install

The problem it solves

An expense of £2,000 is normal for equipment and extraordinary for a meal. Outlier checks need to run within groups, over several fields, with a rule people can explain, and leave a list someone can review.

This block applies Tukey's IQR fences, z-scores or the robust MAD rule to every chosen field within each group, flags each value, lists the outliers with their bounds and scores, and can add capped copies for modelling.

How it works

What goes in

Expense claims

1,200 invented claims with planted problems.

Claim ID Employee Category Amount (GBP) Mileage Days To Submit
EX70000 E138 Equipment 215.23 1
EX70001 E154 Meals 38.23 12
EX70002 E159 Travel 101.32 1450.0 11
EX70003 E149 Meals 26.8 10
EX70004 E150 Travel 123.69 1800.0 7
EX70005 E154 Travel 201.87 2100.0 1

1,200 rows in the sample file.

The options

Option Demo setting What it does
Numeric fields Amount (GBP), Mileage, Days To Submit Leave empty to check every numeric field.
Within groups (optional) Category For example Category.
Key fields for the outlier list Claim ID For example Claim ID.
Method IQR (Tukey's fences) IQR and MAD resist the outliers they look for; z-score suits roughly normal data.
Smallest group to test 10 Groups with fewer values are not tested.

What comes out

Bounds per category and field

Category Field Values Lower Bound Upper Bound Low Outliers High Outliers Median Maximum
Accommodation Amount (GBP) 254 17.11 226.84 0 10 119.15 736.82
Accommodation Days To Submit 254 -6.12 20.88 0 1 7 200
Equipment Amount (GBP) 120 -19.74 596.75 0 5 270.14 2,220.20
Equipment Days To Submit 120 -9 23 0 0 7 14
Meals Amount (GBP) 393 1.71 57.5 1 11 28.52 75.23
Meals Days To Submit 393 -6.5 21.5 0 4 8 140
Travel Amount (GBP) 433 1.14 170.94 1 13 83.76 254.28
Travel Mileage 433 -60 284 0 13 110 2,100
Travel Days To Submit 433 -7.5 20.5 0 1 7 75

Most extreme outliers

Row Number Claim ID Category Field Value Direction Bound Score Beyond Bound
371 EX70370 Accommodation Days To Submit 200 High 20.88 28.04 179.12
6 EX70005 Travel Mileage 2,100 High 284 22.62 1,816
5 EX70004 Travel Mileage 1,800 High 284 19.13 1,516
783 EX70782 Meals Days To Submit 140 High 21.5 18.43 118.50
540 EX70539 Meals Days To Submit 120 High 21.5 15.57 98.5
3 EX70002 Travel Mileage 1,450 High 284 15.06 1,166
1076 EX71075 Equipment Amount (GBP) 2,220.20 High 596.75 12.03 1,623.45
481 EX70480 Meals Days To Submit 95 High 21.5 12 73.5
285 EX70284 Accommodation Amount (GBP) 736.82 High 226.84 11.23 509.98
297 EX70296 Meals Days To Submit 88 High 21.5 11 66.5
Where the outliers are; mileage is tested only for travel, the only category that records it (illustrative data).
Where the outliers are; mileage is tested only for travel, the only category that records it (illustrative data).

Where the outliers are; mileage is tested only for travel, the only category that records it (illustrative data).

The methods differ: z-scores are inflated by the outliers themselves, while the IQR and MAD rules are not.
The methods differ: z-scores are inflated by the outliers themselves, while the IQR and MAD rules are not.

The methods differ: z-scores are inflated by the outliers themselves, while the IQR and MAD rules are not.

Where it pays off

Finance and audit: Expenses and payments

Claims, invoices or payments that are unusually large or small for their category, supplier or employee grade.

Manufacturing: Process and sensor readings

Readings outside the normal band for each machine or product line, before they feed reports.

Data science: Preparing model inputs

Find and cap extreme values per segment before modelling, keeping the originals for reference.

Retail and e-commerce: Orders and prices

Prices or order quantities far from normal for each product, as a check on data entry and pricing errors.

Use cases describe typical scenarios and are illustrative.

Why do this in Omniscope

How it fits into an Omniscope workflow

Data → Outlier Flagger → Filter (Outlier Count > 0) → Report / Email output (review list)

Run within the groups that define 'normal'; Time Series Anomaly Detection covers values over time, and Benford's Law Test covers digit patterns.

Send the outlier list for review, or use the capped fields in a model.

In one step

Three standard rules across many fields and groups, with bounds and a list of outliers.

Try it

  1. Open the demo project (demo.iox on the demo server, or import demo.ioz from this folder): invented expense claims in four categories.
  2. The question: which claims look wrong for their category?
  3. Open the block: amount, mileage and days to submit, within Category, IQR fences. Run it.
  4. Look at the outlier list: impossible mileages, late submissions and very large claims; 60 values in 58 claims.
  5. Switch the method to MAD or z-score and compare the counts; then add capped fields for modelling.

Running in Omniscope

Omniscope workflow
Omniscope workflow

The demo project's workflow: the sample data, the block, and a Validate data check on its output.

Language and libraries

Python. It uses pandas and numpy.

pandas and numpy are part of Omniscope's Docker Python image, and the block was run in both host mode and Docker mode on an Omniscope server, with the same results. It needs nothing else installed.

Tested

The demo workflow ran without errors on an Omniscope server, giving 1,200 records in Rows, 60 in Outliers and 12 in Bounds. Automated tests cover normal data, empty input, wrong types and large input.

Reference

Fields it reads

NameTypeWhat it does
Numeric fieldsFieldsLeave empty to check every numeric field.
Within groups (optional)FieldsFor example Category.
Key fields for the outlier listFieldsFor example Claim ID.

Options

NameTypeWhat it does
MethodChoiceIQR and MAD resist the outliers they look for; z-score suits roughly normal data.
MultiplierNumber0 = the method's default (1.5, 3 or 3.5).
Smallest group to testWhole numberGroups with fewer values are not tested.
Add capped (winsorised) fieldsYes / no

Outputs

OutputWhat it holds
RowsThe input with an outlier flag per field, Outlier Count and Outlier Fields (and capped fields if chosen).
OutliersOne row per outlying value: row number, keys, group, field, value, direction, bound, score.
BoundsPer field and group: values, bounds, low and high counts, share, minimum, median, maximum.