Class: LightGBM::Dataset
- Inherits:
-
Object
- Object
- LightGBM::Dataset
- Includes:
- Utils
- Defined in:
- lib/lightgbm/dataset.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #feature_names ⇒ Object
- #feature_names=(feature_names) ⇒ Object
- #group=(group) ⇒ Object
- #handle_pointer ⇒ Object
-
#initialize(data, label: nil, weight: nil, group: nil, params: nil, reference: nil, used_indices: nil, categorical_feature: "auto", feature_names: nil) ⇒ Dataset
constructor
A new instance of Dataset.
- #label ⇒ Object
- #label=(label) ⇒ Object
- #num_data ⇒ Object
- #num_feature ⇒ Object
-
#reference=(reference) ⇒ Object
TODO only update reference if not in chain.
- #save_binary(filename) ⇒ Object
- #subset(used_indices, params: nil) ⇒ Object
- #weight ⇒ Object
- #weight=(weight) ⇒ Object
Constructor Details
#initialize(data, label: nil, weight: nil, group: nil, params: nil, reference: nil, used_indices: nil, categorical_feature: "auto", feature_names: nil) ⇒ Dataset
Returns a new instance of Dataset.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/lightgbm/dataset.rb', line 5 def initialize(data, label: nil, weight: nil, group: nil, params: nil, reference: nil, used_indices: nil, categorical_feature: "auto", feature_names: nil) @data = data @label = label @weight = weight @group = group @params = params @reference = reference @used_indices = used_indices @categorical_feature = categorical_feature @feature_names = feature_names construct end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/lightgbm/dataset.rb', line 3 def data @data end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/lightgbm/dataset.rb', line 3 def params @params end |
Class Method Details
.finalize(pointer) ⇒ Object
101 102 103 104 |
# File 'lib/lightgbm/dataset.rb', line 101 def self.finalize(pointer) # must use proc instead of stabby lambda proc { FFI.LGBM_DatasetFree(pointer) } end |
Instance Method Details
#feature_names ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lightgbm/dataset.rb', line 27 def feature_names # must preallocate space num_feature_names = ::FFI::MemoryPointer.new(:int) out_buffer_len = ::FFI::MemoryPointer.new(:size_t) len = 1000 out_strs = ::FFI::MemoryPointer.new(:pointer, len) buffer_len = 255 str_ptrs = len.times.map { ::FFI::MemoryPointer.new(:char, buffer_len) } out_strs.write_array_of_pointer(str_ptrs) check_result FFI.LGBM_DatasetGetFeatureNames(handle_pointer, len, num_feature_names, buffer_len, out_buffer_len, out_strs) str_ptrs[0, num_feature_names.read_int].map(&:read_string) end |
#feature_names=(feature_names) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/lightgbm/dataset.rb', line 55 def feature_names=(feature_names) @feature_names = feature_names c_feature_names = ::FFI::MemoryPointer.new(:pointer, feature_names.size) c_feature_names.write_array_of_pointer(feature_names.map { |v| ::FFI::MemoryPointer.from_string(v) }) check_result FFI.LGBM_DatasetSetFeatureNames(handle_pointer, c_feature_names, feature_names.size) end |
#group=(group) ⇒ Object
50 51 52 53 |
# File 'lib/lightgbm/dataset.rb', line 50 def group=(group) @group = group set_field("group", group, type: :int32) end |
#handle_pointer ⇒ Object
97 98 99 |
# File 'lib/lightgbm/dataset.rb', line 97 def handle_pointer @handle.read_pointer end |
#label ⇒ Object
19 20 21 |
# File 'lib/lightgbm/dataset.rb', line 19 def label field("label") end |
#label=(label) ⇒ Object
40 41 42 43 |
# File 'lib/lightgbm/dataset.rb', line 40 def label=(label) @label = label set_field("label", label) end |
#num_data ⇒ Object
71 72 73 74 75 |
# File 'lib/lightgbm/dataset.rb', line 71 def num_data out = ::FFI::MemoryPointer.new(:int) check_result FFI.LGBM_DatasetGetNumData(handle_pointer, out) out.read_int end |
#num_feature ⇒ Object
77 78 79 80 81 |
# File 'lib/lightgbm/dataset.rb', line 77 def num_feature out = ::FFI::MemoryPointer.new(:int) check_result FFI.LGBM_DatasetGetNumFeature(handle_pointer, out) out.read_int end |
#reference=(reference) ⇒ Object
TODO only update reference if not in chain
63 64 65 66 67 68 69 |
# File 'lib/lightgbm/dataset.rb', line 63 def reference=(reference) if reference != @reference @reference = reference free_handle construct end end |
#save_binary(filename) ⇒ Object
83 84 85 |
# File 'lib/lightgbm/dataset.rb', line 83 def save_binary(filename) check_result FFI.LGBM_DatasetSaveBinary(handle_pointer, filename) end |
#subset(used_indices, params: nil) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/lightgbm/dataset.rb', line 87 def subset(used_indices, params: nil) # categorical_feature passed via params params ||= self.params Dataset.new(nil, params: params, reference: self, used_indices: used_indices ) end |
#weight ⇒ Object
23 24 25 |
# File 'lib/lightgbm/dataset.rb', line 23 def weight field("weight") end |
#weight=(weight) ⇒ Object
45 46 47 48 |
# File 'lib/lightgbm/dataset.rb', line 45 def weight=(weight) @weight = weight set_field("weight", weight) end |