Code Monkey home page Code Monkey logo

Comments (3)

wdm0006 avatar wdm0006 commented on July 24, 2024

Do you see the same error in v1.2.6?

from category_encoders.

gavin-s-smith avatar gavin-s-smith commented on July 24, 2024

Yes, I can confirm this error (same code) v1.2.6.

This looks like a bug. The statement block in question is:

if X[~X['D'].isin([str(x[1]) for x in switch.get('mapping')])].shape[0] > 0:
    raise ValueError('Unexpected categories found in %s' % (switch.get('col'),))

At this point the code is looping over each column and converting the string representation to the ordinal one - if there is no match in the previously learnt mapping then it is mapped to NaN.

Then we look to impute and/or check which, assuming we've picked the handle_unknown == 'error' option, is when the above block is run.

The above check is a generic one though, and just checks if the (newly mapped) ordinal encoding values in the column X['D'] are valid. Of course since we are looping over columns in X (and in any case have an arbitrary DataFrame) the column 'D' almost certainly doesn't exist and this is a bug. The current column is given by switch.get('col'). As such the corrected code is:

if X[~X[switch.get('col')].isin([str(x[1]) for x in switch.get('mapping')])].shape[0] > 0:
    raise ValueError('Unexpected categories found in %s' % (switch.get('col'),))

from category_encoders.

wdm0006 avatar wdm0006 commented on July 24, 2024

from category_encoders.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.