Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LightGBM model summary raises ArgumentError #21

Closed
timcraft opened this issue Nov 6, 2020 · 1 comment
Closed

LightGBM model summary raises ArgumentError #21

timcraft opened this issue Nov 6, 2020 · 1 comment

Comments

@timcraft
Copy link

timcraft commented Nov 6, 2020

Calling #summary on a LightGBM model raises a comparison of Array with Array failed (ArgumentError) exception, which is coming from the #sort_by call in Eps::LightGBM#_summary. I don't know how to best add test coverage to expose the issue in the tests, but I can demonstrate it using data from LightGBMTest:

test_data = [
  ["drv", 1029],
  ["class", 144],
  ["displ", 4322],
  ["year", 1126],
  ["cyl", 320],
  [["model", "4wd"], 364],
  [["model", "pickup"], 160],
  [["model", "2wd"], 72],
  [["model", "a4"], 0],
  [["model", "awd"], 0]]

test_data << ["foo", 0]

p test_data.sort_by { |k, v| [-v, k] }

ArgumentError will be raised if there are any string keys and array keys with the same value.

This is because strings can't be compared to arrays:

irb(main):001:0> ["model", "awd"] <=> "foo"
=> nil

Converting all the keys to strings using #display_field before the call to #sort_by fixes the issue, so does flattening the temporary arrays inside the #sort_by block.

@ankane ankane closed this as completed in ea00277 Nov 6, 2020
@ankane
Copy link
Owner

ankane commented Nov 6, 2020

Hey @timcraft, thanks for reporting and debugging the cause! Fixed on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants