liveBook · Manning

Prediction averaging

As explained in Outlier Detection in Python

Score averaging is the aggregation of multiple detector scores or scores obtained under multiple parameter values by computing their mean.

Prediction averaging aggregates detector scores across multiple parameter values or detectors, typically by computing a mean. It reduces dependence on one potentially poor configuration and can make outlier rankings more robust. section 8.1.1

A practical workflow is:

  • Run one detector with several parameter values, such as KNN with k = 5, 10, 20, 50, and 100, and collect its scores. section 8.1.1
  • Normalize scores from different detectors before combining them, using MinMaxScaler so their scales are comparable. section 8.1.1
  • Average the resulting scores and inspect the ranking rather than treating every flagged point as automatically meaningful. section 8.1.1

KNN across parameter values

A KNN detector can fit once for each selected k, store each decision-score vector in a pandas dataframe, and combine the rows into one score column. Averaging several imperfect k values can outperform relying on one estimated optimum. section 8.1.1

Listing 8.2 Averaging over multiple detectors
scaler = MinMaxScaler()
for col_name in scores_df.columns:
  scores_df[col_name] = \
    scaler.fit_transform(np.array(scores_df[col_name]).reshape(-1, 1))
scores_df['Avg Score'] = scores_df.sum(axis=1)

Shows the implementation pattern for scaling detector scores and creating a combined score. section 8.1.1

How Outlier Detection in Python covers it

How deep it goes
Explains parameter and detector aggregation with concise implementation patterns, but stops short of formal ensemble analysis.
Examples
Uses KNN scores across five k values, six-detector combinations, score dataframes, and MinMaxScaler.
What it assumes
Assumes access to detector scores and parameterized detectors, while introducing the need to align score scales before combining them.
What you can do after
Apply it via detector score collection, normalization, and aggregation across parameters or detectors.
How it connects
Connects KNN, LOF, COF, MinMax scaling, outlier detection, and parameter selection.

Also explained in

Compare how 2 books explain prediction averaging →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Outlier Detection in Python. The section links point to the parts of the book it draws on.