liveBook · Manning

Hyperparameter

As explained in Outlier Detection in Python

A hyperparameter is a configuration value set before model training or algorithm execution that controls the model or algorithm's behavior.

A hyperparameter is a configuration value chosen before model training or algorithm execution. It controls how a detector behaves rather than being learned from the data. section 14.3.3 section 6.1

In outlier detection, hyperparameters can determine neighborhood size, cluster density, distance calculations, or other detector behavior. Their values can materially change which records are flagged. section 4.11 section 14.3.3

Common tuning targets include:

  • DBSCAN's eps parameter, which changes cluster membership and the number of flagged outliers. section 4.11
  • KNN's k parameter, which can make nearest-neighbor detection sensitive to the selected neighborhood size. section 4.11
  • The number of clusters and the distance metric used by clustering-based or distance-based detectors. section 14.3.3

A useful selection process evaluates several values rather than trusting defaults or one apparently optimal setting. AUROC can compare detectors and tune preprocessing, feature engineering, and hyperparameters when labeled or doped data are available. Prefer a range of values that performs well, because synthetic anomalies and real anomalies may differ. section 8.5.3 section 6.1

Varying DBSCAN eps

On baseball data, default DBSCAN parameters flag more records than is useful. Setting eps to 2.0 produces 1,255 inliers and 85 outliers. Running DBSCAN across eps values from 0.1 through 4.9 and summing each row's outlier flags produces a more parameter-robust score. section 4.11

Listing 4.5 Looping through the eps parameter for DBSCAN
df['DBSCAN Score'] = [0] * len(df)
for eps in np.arange(0.1, 5.0, 0.1):
    df['DBSCAN Score'] += \
       np.where(DBSCAN(eps=eps).fit_predict(df) < 0, 1, 0)    
sns.histplot(df['DBSCAN Score'])
plt.show()

Shows a concise parameter sweep that converts binary DBSCAN results across eps values into numeric robustness scores. section 4.11

How Outlier Detection in Python covers it

How deep it goes
Explains parameter effects, sweeps, evaluation, and robust ranges, but stops short of deriving detector-specific optimization theory.
Examples
Uses baseball-data DBSCAN and KNN experiments, PyOD detectors, synthetic anomalies, and AUROC-based comparisons.
What it assumes
Assumes familiarity with outlier detectors and their outputs while emphasizing that defaults may be suboptimal for a dataset or goal.
What you can do after
Tune detector configurations, compare parameter ranges, and build ensembles less dependent on a single setting.
How it connects
Connects detector selection with DBSCAN, KNN, clustering, distance metrics, preprocessing, feature engineering, and ensembles.

Also explained in

Compare how 19 books explain hyperparameter →

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.