Skip to content

[BUG] ValueDifferenceMetric.pairwise silently ignores extra features #1198

Description

@aswanth-07

Describe the bug

After ValueDifferenceMetric is fitted, pairwise does not validate that X and Y have the fitted number of features. Extra columns are silently ignored because the distance loop only processes self.n_features_in_ columns.

This can produce a plausible distance matrix that omits part of the supplied feature vectors instead of reporting a schema mismatch.

Steps/Code to Reproduce

import numpy as np

from imblearn.metrics.pairwise import ValueDifferenceMetric

X_train = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.int32)
y = np.array([0, 0, 1, 1])
vdm = ValueDifferenceMetric().fit(X_train, y)

X_valid = np.array([[0, 0], [1, 1]], dtype=np.int32)
X_extra = np.column_stack([X_valid, [999, 999]])

print(vdm.pairwise(X_valid))
print(vdm.pairwise(X_extra))
print(np.array_equal(vdm.pairwise(X_valid), vdm.pairwise(X_extra)))

Expected Results

pairwise(X_extra) should raise a ValueError because the metric was fitted with two features but received three. The same validation should apply when a mismatched array is passed as Y.

Actual Results

The extra feature is silently ignored:

[[0. 4.]
 [4. 0.]]
[[0. 4.]
 [4. 0.]]
True

Versions

Windows-10-10.0.26200-SP0
Python 3.10.11
NumPy 2.2.6
SciPy 1.15.3
Scikit-Learn 1.7.2
Imbalanced-Learn 0.15.dev0 (master at 8504e95f)

AI assistance

OpenAI Codex was used to audit the code, reproduce and de-duplicate this issue, and draft this report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions