Skip to content

nonconform v2.1.0

Latest

Choose a tag to compare

@OliverHennhoefer OliverHennhoefer released this 20 Nov 13:10
· 36 commits to main since this release
fd61685

nonconform 2.1.0 makes ConformalDetector a drop-in scikit-learn estimator and adds Python 3.11 support.

pip install -U nonconform

Added

  • ConformalDetector is now a scikit-learn BaseEstimator, so clone works and it can be the last step of a Pipeline, whatever detector it wraps. predict(X) applies select(X, alpha=alpha) to the whole batch and returns -1 for selected anomalies and 1 otherwise; alpha is a new constructor parameter (default 0.05), and predict leaves last_result unchanged. n_features_in_ and feature_names_in_ are set by fit() and calibrate().
  • strategy is optional and defaults to Split(). Passing a string such as "split" or the class Split instead of an instance raises a TypeError that names the fix.
  • The detector may be a plain scoring function f(X) -> scores, treated as already fitted, or an object with only fit and decision_function. With an identity function, precomputed scores can be calibrated and selected.
  • ConformalResult.to_frame() returns the scores, p-values, and weights as a DataFrame that keeps the index of a pandas test batch.
  • Column names are checked at inference: a detector fitted on a DataFrame rejects renamed or reordered test columns and warns when test data has no column names, with scikit-learn's messages. SciPy sparse input raises a TypeError that suggests X.toarray().

Changed

  • nonconform now supports Python 3.11 (requires-python = ">=3.11"). CI tests 3.11, 3.12 and 3.13.
  • The NumPy floor is now 2.0 (was 2.2). The test suite passes on the lowest declared versions: NumPy 2.0.0, pandas 2.2.2, SciPy 1.13.1 and scikit-learn 1.5.2.
  • The SciPy floor is now 1.13.1, the first release built against NumPy 2.
  • oddball (in the data and all extras) requires Python 3.12, so on Python 3.11 those extras install without it. PyArrow is still installed.
  • Omitting score_polarity for a detector nonconform does not recognize now logs a warning that higher-is-anomalous was assumed. The resolved polarity is unchanged.
  • "Detector has no random_state parameter" is now logged at debug level instead of as a warning, since it fired for every deterministic detector.
  • The empty-selection p-value floor warning now also suggests checking score_polarity, and the error for blocked PyOD detectors names detectors that work.
  • DataFrames now reach scikit-learn detectors and Pipelines unchanged instead of being converted to NumPy, so a ColumnTransformer can select columns by name. PyOD and custom detectors still receive NumPy arrays.
  • get_params() now returns the objects passed to the constructor or set_params(), as scikit-learn requires, instead of detached copies. The fitted detector still uses its own copies, so editing a returned object changes later clones but not the current detector.
  • Shape errors use scikit-learn's wording, for example "X has 2 features, but ConformalDetector is expecting 3 features as input."

Fixed

  • A scikit-learn Pipeline now takes its score polarity from its final step. Before, make_pipeline(StandardScaler(), IsolationForest()) with score_polarity omitted was treated as higher-is-anomalous, which silently inverted every decision, and score_polarity="auto" raised. Pipelines whose final step is a blocked batch-adaptive PyOD detector are now rejected too.
  • seed now reaches every Pipeline step that exposes random_state, and n_jobs and contamination reach the final step (for example isolationforest__random_state), so seeded pipeline runs are reproducible.
  • LocalOutlierFactor() without novelty=True now fails at construction with a message naming novelty=True, instead of an AttributeError at scoring.

Full changelog: v2.0.1...v2.1.0