MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / load_from_csc

Function load_from_csc

tests/c_api_test/test_.py:124–158  ·  view source on GitHub ↗
(filename, reference)

Source from the content-addressed store, hash-verified

122
123
124def load_from_csc(filename, reference):
125 data = []
126 label = []
127 with open(filename, 'r') as inp:
128 for line in inp.readlines():
129 values = line.split('\t')
130 data.append([float(x) for x in values[1:]])
131 label.append(float(values[0]))
132 mat = np.array(data)
133 label = np.array(label, dtype=np.float32)
134 csr = sparse.csc_matrix(mat)
135 handle = ctypes.c_void_p()
136 ref = None
137 if reference is not None:
138 ref = reference
139
140 LIB.LGBM_DatasetCreateFromCSC(
141 c_array(ctypes.c_int, csr.indptr),
142 dtype_int32,
143 c_array(ctypes.c_int, csr.indices),
144 csr.data.ctypes.data_as(ctypes.POINTER(ctypes.c_void_p)),
145 dtype_float64,
146 ctypes.c_int64(len(csr.indptr)),
147 ctypes.c_int64(len(csr.data)),
148 ctypes.c_int64(csr.shape[0]),
149 c_str('max_bin=15'),
150 ref,
151 ctypes.byref(handle))
152 num_data = ctypes.c_long()
153 LIB.LGBM_DatasetGetNumData(handle, ctypes.byref(num_data))
154 num_feature = ctypes.c_long()
155 LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature))
156 LIB.LGBM_DatasetSetField(handle, c_str('label'), c_array(ctypes.c_float, label), len(label), 0)
157 print('#data: %d #feature: %d' % (num_data.value, num_feature.value))
158 return handle
159
160
161def load_from_mat(filename, reference):

Callers 1

test_datasetFunction · 0.85

Calls 5

readlinesMethod · 0.80
appendMethod · 0.80
arrayMethod · 0.80
c_arrayFunction · 0.70
c_strFunction · 0.70

Tested by

no test coverage detected