Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Missing handle_unknown parameter in OrdinalEncoder #12365

@tomasprinda

Description

@tomasprinda

Description

When trying to fit OrdinalEncoder with predefined string categorical values it raises an expection of

AttributeError: 'OrdinalEncoder' object has no attribute 'handle_unknown'

Steps/Code to Reproduce

import numpy as np
from sklearn.preprocessing import OrdinalEncoder

a = np.array([["A", "A", "B"]]).T

enc = OrdinalEncoder([["A", "B"]])
enc.fit(a)

Expected Results

No error is thrown.

Actual Results

/usr/local/lib/python3.6/dist-packages/sklearn/externals/joblib/externals/cloudpickle/cloudpickle.py:47: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
Traceback (most recent call last):
  File "bug.py", line 9, in <module>
    enc.fit(a)
  File "/usr/local/lib/python3.6/dist-packages/sklearn/preprocessing/_encoders.py", line 774, in fit
    self._fit(X)
  File "/usr/local/lib/python3.6/dist-packages/sklearn/preprocessing/_encoders.py", line 85, in _fit
    if self.handle_unknown == 'error':
AttributeError: 'OrdinalEncoder' object has no attribute 'handle_unknown'

Versions

System
------
    python: 3.6.6 (default, Sep 12 2018, 18:26:19)  [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]
executable: /usr/bin/python3
   machine: Linux-4.15.0-36-generic-x86_64-with-Ubuntu-18.04-bionic

BLAS
----
    macros: 
  lib_dirs: 
cblas_libs: cblas

Python deps
-----------
       pip: 18.0
setuptools: 39.0.1
   sklearn: 0.20.0
     numpy: 1.15.2
     scipy: 1.1.0
    Cython: None
    pandas: 0.23.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions