Skip to content

KBinsDiscretizer doesn't handle NAs #19920

@david-cortes

Description

@david-cortes

If I try to pass some input to KBinsDiscretizer that would contain NaNs, it will throw an error instead of ignoring the NAs:

import numpy as np
from sklearn.preprocessing import KBinsDiscretizer

X = np.arange(10).reshape((-1,1))
X[2] = np.nan
kb = KBinsDiscretizer(encode="ordinal", strategy="quantile")
kb.fit(X)
ValueError: cannot convert float NaN to integer

The bins could still be calculated if one ignores the NAs and outputs them as np.nan in the transformation.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions