Class: Xgb::DMatrix

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/xgb/dmatrix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, label: nil, weight: nil, missing: Float::NAN) ⇒ DMatrix

Returns a new instance of DMatrix.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/xgb/dmatrix.rb', line 5

def initialize(data, label: nil, weight: nil, missing: Float::NAN)
  @data = data
  @label = label
  @weight = weight

  c_data = ::FFI::MemoryPointer.new(:float, data.count * data.first.count)
  c_data.put_array_of_float(0, data.flatten)
  @handle = ::FFI::MemoryPointer.new(:pointer)
  check_result FFI.XGDMatrixCreateFromMat(c_data, data.count, data.first.count, missing, @handle)

  set_float_info("label", label) if label
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/xgb/dmatrix.rb', line 3

def data
  @data
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/xgb/dmatrix.rb', line 3

def label
  @label
end

#weightObject (readonly)

Returns the value of attribute weight.



3
4
5
# File 'lib/xgb/dmatrix.rb', line 3

def weight
  @weight
end

Instance Method Details

#handle_pointerObject



24
25
26
# File 'lib/xgb/dmatrix.rb', line 24

def handle_pointer
  @handle.read_pointer
end

#num_colObject



18
19
20
21
22
# File 'lib/xgb/dmatrix.rb', line 18

def num_col
  out = ::FFI::MemoryPointer.new(:long)
  FFI.XGDMatrixNumCol(handle_pointer, out)
  out.read_long
end