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

_summary': undefined method feature_importance' for nil:NilClass (NoMethodError) #15

Closed
rmontgomery429 opened this issue Jan 2, 2020 · 1 comment

Comments

@rmontgomery429
Copy link

Given you've installed the prerequisites:

gem install 'eps'
brew install libomp

And a have a file as such:

# test.rb
#!/home/test/.rvm/rubies/ruby-2.6.3/bin/ruby
require 'eps'

data = [
  {bedrooms: 1, bathrooms: 1, price: 100000},
  {bedrooms: 2, bathrooms: 1, price: 125000},
  {bedrooms: 2, bathrooms: 2, price: 135000},
  {bedrooms: 3, bathrooms: 2, price: 162000}
]

model = Eps::Model.new(data, target: :price)

File.write("model.pmml", model.to_pmml)

pmml = File.read("model.pmml")

model = Eps::Model.load_pmml(pmml)

puts model.summary

You will received an error:

Traceback (most recent call last):
        4: from ./test.rb:21:in `<main>'
        3: from /workspace/.rvm/gems/eps-0.3.2/lib/eps/model.rb:60:in `method_missing'
        2: from /workspace/.rvm/gems/eps-0.3.2/lib/eps/model.rb:60:in `public_send'
        1: from /workspace/.rvm/gems/eps-0.3.2/lib/eps/base_estimator.rb:69:in `summary'
/workspace/.rvm/gems/eps-0.3.2/lib/eps/lightgbm.rb:7:in `_summary': undefined method `feature_importance' for nil:NilClass (NoMethodError)

Which is this line:

importance = @booster.feature_importance

I assume the instance variable just isn't set at that point so I may just misunderstand how the file is to be used but I would think that I would be able to load the model and use it to get the summary without needing to re-train.

Is that not the case?

@ankane ankane closed this as completed in 5211f40 Jan 2, 2020
@ankane
Copy link
Owner

ankane commented Jan 2, 2020

Hey @rmontgomery429, nice find. Unfortunately, the summary isn't available for loaded models, as the feature importance isn't stored in the PMML. I added a better error message for this 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