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

Function load_from_csr

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

Source from the content-addressed store, hash-verified

85
86
87def load_from_csr(filename, reference):
88 data = []
89 label = []
90 with open(filename, 'r') as inp:
91 for line in inp.readlines():
92 values = line.split('\t')
93 data.append([float(x) for x in values[1:]])
94 label.append(float(values[0]))
95 mat = np.array(data)
96 label = np.array(label, dtype=np.float32)
97 csr = sparse.csr_matrix(mat)
98 handle = ctypes.c_void_p()
99 ref = None
100 if reference is not None:
101 ref = reference
102
103 LIB.LGBM_DatasetCreateFromCSR(
104 c_array(ctypes.c_int, csr.indptr),
105 dtype_int32,
106 c_array(ctypes.c_int, csr.indices),
107 csr.data.ctypes.data_as(ctypes.POINTER(ctypes.c_void_p)),
108 dtype_float64,
109 ctypes.c_int64(len(csr.indptr)),
110 ctypes.c_int64(len(csr.data)),
111 ctypes.c_int64(csr.shape[1]),
112 c_str('max_bin=15'),
113 ref,
114 ctypes.byref(handle))
115 num_data = ctypes.c_long()
116 LIB.LGBM_DatasetGetNumData(handle, ctypes.byref(num_data))
117 num_feature = ctypes.c_long()
118 LIB.LGBM_DatasetGetNumFeature(handle, ctypes.byref(num_feature))
119 LIB.LGBM_DatasetSetField(handle, c_str('label'), c_array(ctypes.c_float, label), len(label), 0)
120 print('#data: %d #feature: %d' % (num_data.value, num_feature.value))
121 return handle
122
123
124def load_from_csc(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