Clustering, density estimation, and anomaly detection · Anomaly detection · UCL053 · Algorithm
Connectivity-Based Outlier Factor (COF)
Detect local anomalies using connectivity along a neighborhood's chaining structure. It was designed to handle patterns where a simple density-volume interpretation is problematic, such as approximately linear local…
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page.
- Nearest-neighbor outlier scores Verified in Python and R
Do it in CodeSplash Run it on your own data, in Python or R.
- Availability
- Runs in CodeSplash
- Code example
- Component demo, not a trained model
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through discover.knn_outlier. The reference's example ran in Python and R here, and they agree.
- The reference's record
- Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.
Purpose
Detect local anomalies using connectivity along a neighborhood's chaining structure. It was designed to handle patterns where a simple density-volume interpretation is problematic, such as approximately linear local groups.
Question / hypotheses
Which observations deviate from the chosen reference notion of normality, and at what operational alert rate? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.
Architecture / computational structure
Set-based neighbor chaining followed by local chaining-distance ratios.
Assumptions
The chaining distance requires the specified path construction; replacing it with the ordinary mean neighbor distance turns the method into another detector. Noise bridges and sparse local neighborhoods can change paths substantially.
Formula / computational definition
Construct a set-based nearest-neighbor path and its weighted average chaining distance . Then under a -neighbor convention. Values above one indicate weaker local connectivity than neighbors possess.
Parameters and notation
Learned or fitted quantities: Local paths, average chaining distances, and scores. User-set hyperparameters/design choices: Choose neighborhood size, distance, scaling, and computational strategy. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.
Fitting, fine-tuning, and adaptation
Neural fine-tuning is not applicable to this classical detector. Refit the reference model when its population changes, then recalibrate an alert threshold on a separate normal holdout. Tune sensitivity without using final-test anomaly labels repeatedly.
How to use and calibrate
Inspect score sensitivity to , chaining paths for flagged observations, and detection on elongated versus compact normal patterns. Compare with LOF under identical preprocessing and held-out labels when available.
Example application
Flag weakly connected records in an approximately linear normal pattern. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.
Interpretation / pitfalls
Watch out
The reported result is conditional on the representation and objective. An alert is a screening result, not a diagnosis or a calibrated posterior probability. Evaluate both ranking and the decision threshold.
Python and R code examples
PyOD implements COF. R needs a custom path-construction implementation or bridge. The paired calculation demonstrates the final ratio using supplied chaining distances; it does not silently equate those distances with ordinary nearest-neighbor radii.
Component: COF ratio from supplied average chaining distances. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.
Python and R
The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.
Component demo, not a trained model — COF ratio from supplied average chaining distances. · needs numpy
import numpy as np
self_chain=2.; neighbor_chain=np.array([.8,1.,1.2])
result=len(neighbor_chain)*self_chain/neighbor_chain.sum()
print(result)
Component demo, not a trained model — COF ratio from supplied average chaining distances.
self_chain=2; neighbor_chain=c(.8,1,1.2)
result=length(neighbor_chain)*self_chain/sum(neighbor_chain)
print(result)
Sources
- Source 1pyod.readthedocs.io
From the CodeSplash reference, entry UCL053.