Class: LightGBM::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/lightgbm/model.rb

Direct Known Subclasses

Classifier, Ranker, Regressor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num_leaves: 31, learning_rate: 0.1, n_estimators: 100, objective: nil, **options) ⇒ Model

Returns a new instance of Model.



5
6
7
8
9
10
11
12
# File 'lib/lightgbm/model.rb', line 5

def initialize(num_leaves: 31, learning_rate: 0.1, n_estimators: 100, objective: nil, **options)
  @params = {
    num_leaves: num_leaves,
    learning_rate: learning_rate
  }.merge(options)
  @params[:objective] = objective if objective
  @n_estimators = n_estimators
end

Instance Attribute Details

#boosterObject (readonly)

Returns the value of attribute booster.



3
4
5
# File 'lib/lightgbm/model.rb', line 3

def booster
  @booster
end

Instance Method Details

#best_iterationObject



22
23
24
# File 'lib/lightgbm/model.rb', line 22

def best_iteration
  @booster.best_iteration
end

#feature_importancesObject



26
27
28
# File 'lib/lightgbm/model.rb', line 26

def feature_importances
  @booster.feature_importance
end

#load_model(fname) ⇒ Object



18
19
20
# File 'lib/lightgbm/model.rb', line 18

def load_model(fname)
  @booster = Booster.new(params: @params, model_file: fname)
end

#save_model(fname) ⇒ Object



14
15
16
# File 'lib/lightgbm/model.rb', line 14

def save_model(fname)
  @booster.save_model(fname)
end