ankane / eps

Machine learning for Ruby
MIT License
643 stars 15 forks source link

convert to floating point to make the comparison #23

Closed frankstratton closed 2 years ago

frankstratton commented 2 years ago

I have an integer field that sometimes, but not always, triggers this error. It looks like the comparison is reading a string from the pmml file and trying to compare against an int value. The following change fixes my issue but I'm not sure if it causes issues in other places.


/Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:97:in `<=': comparison of Integer with String failed (ArgumentError)
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:97:in `matches?'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:106:in `node_score'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:108:in `block in node_score'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:107:in `each'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:107:in `node_score'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:69:in `block (2 levels) in sum_trees'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:68:in `each'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:68:in `block in sum_trees'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:66:in `map'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:66:in `sum_trees'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/evaluators/lightgbm.rb:35:in `predict'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/base_estimator.rb:81:in `_predict'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/base_estimator.rb:12:in `predict'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/model.rb:60:in `public_send'
    from /Users/frank.stratton/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/eps-0.3.8/lib/eps/model.rb:60:in `method_missing'
    from test.rb:6:in `<top (required)>'```
ankane commented 2 years ago

Hey @frankstratton, thanks for the PR. Are you using Eps to generate the PMML? Also, can you share either code or PMML to reproduce the issue?

frankstratton commented 2 years ago

I am using EPS to generate the PMML. Unfortunately I cannot share the model itself. I'm trying to edit it down to something minimal that still has the error but it's not very easy to do. I've tracked it down to this node in the file, not sure if that's helpful to you or not. In my test years_experience is 4 and it dies on the lessOrEqual check.


  <Node score="-0.013125003863849048">
    <SimplePredicate field="years_experience" operator="lessOrEqual" value="5.500000000000001"/>
    <Node score="0.011133097502084278">
      <SimplePredicate field="job_descriptions(developing)" operator="greaterThan" value="1.0000000180025095e-35"/>
      <Node score="-0.0407953976683559">
      <SimplePredicate field="job_descriptions(problems)" operator="greaterThan" value="1.0000000180025095e-35"/>
      </Node>
    </Node>
    <Node score="0.03872677470342471">
      <SimplePredicate field="short_phrase(robotics)" operator="greaterThan" value="1.0000000180025095e-35"/>
    </Node>
    <Node score="0.009757622225846552">
      <SimplePredicate field="job_descriptions(pipeline)" operator="greaterThan" value="1.0000000180025095e-35"/>
    </Node>
  </Node>```
ankane commented 2 years ago

Thanks @frankstratton, it looks like lessOrEqual operators weren't being cast during PMML loading. Can you see if the commit above fixes it?

gem 'eps', github: 'ankane/eps'
frankstratton commented 2 years ago

works great thanks! Will you be releasing a new version of the gem soon?

ankane commented 2 years ago

Thanks for confirming. Just pushed a new release.