Class: XGBoost::Model
- Inherits:
-
Object
show all
- Defined in:
- lib/xgboost/model.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(n_estimators: 100, importance_type: "gain", early_stopping_rounds: nil, **options) ⇒ Model
Returns a new instance of Model.
5
6
7
8
9
10
|
# File 'lib/xgboost/model.rb', line 5
def initialize(n_estimators: 100, importance_type: "gain", early_stopping_rounds: nil, **options)
@params = options
@n_estimators = n_estimators
@importance_type = importance_type
@early_stopping_rounds = early_stopping_rounds
end
|
Instance Attribute Details
#booster ⇒ Object
Returns the value of attribute booster.
3
4
5
|
# File 'lib/xgboost/model.rb', line 3
def booster
@booster
end
|
Instance Method Details
#feature_importances ⇒ Object
25
26
27
28
29
30
|
# File 'lib/xgboost/model.rb', line 25
def feature_importances
score = @booster.score(importance_type: @importance_type)
scores = @booster.feature_names.map { |k| score[k] || 0.0 }
total = scores.sum.to_f
scores.map { |s| s / total }
end
|
#load_model(fname) ⇒ Object
21
22
23
|
# File 'lib/xgboost/model.rb', line 21
def load_model(fname)
@booster = Booster.new(params: @params, model_file: fname)
end
|
#predict(data) ⇒ Object
12
13
14
15
|
# File 'lib/xgboost/model.rb', line 12
def predict(data)
dmat = DMatrix.new(data)
@booster.predict(dmat)
end
|
#save_model(fname) ⇒ Object
17
18
19
|
# File 'lib/xgboost/model.rb', line 17
def save_model(fname)
@booster.save_model(fname)
end
|