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

Function test_booster

tests/c_api_test/test_.py:217–280  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

215
216
217def test_booster():
218 train = load_from_mat(os.path.join(os.path.dirname(os.path.realpath(__file__)),
219 '../../examples/binary_classification/binary.train'), None)
220 test = load_from_mat(os.path.join(os.path.dirname(os.path.realpath(__file__)),
221 '../../examples/binary_classification/binary.test'), train)
222 booster = ctypes.c_void_p()
223 LIB.LGBM_BoosterCreate(
224 train,
225 c_str("app=binary metric=auc num_leaves=31 verbose=0"),
226 ctypes.byref(booster))
227 LIB.LGBM_BoosterAddValidData(booster, test)
228 is_finished = ctypes.c_int(0)
229 for i in range(1, 51):
230 LIB.LGBM_BoosterUpdateOneIter(booster, ctypes.byref(is_finished))
231 result = np.array([0.0], dtype=np.float64)
232 out_len = ctypes.c_ulong(0)
233 LIB.LGBM_BoosterGetEval(
234 booster,
235 0,
236 ctypes.byref(out_len),
237 result.ctypes.data_as(ctypes.POINTER(ctypes.c_double)))
238 if i % 10 == 0:
239 print('%d iteration test AUC %f' % (i, result[0]))
240 LIB.LGBM_BoosterSaveModel(booster, 0, -1, c_str('model.txt'))
241 LIB.LGBM_BoosterFree(booster)
242 free_dataset(train)
243 free_dataset(test)
244 booster2 = ctypes.c_void_p()
245 num_total_model = ctypes.c_long()
246 LIB.LGBM_BoosterCreateFromModelfile(
247 c_str('model.txt'),
248 ctypes.byref(num_total_model),
249 ctypes.byref(booster2))
250 data = []
251 with open(os.path.join(os.path.dirname(os.path.realpath(__file__)),
252 '../../examples/binary_classification/binary.test'), 'r') as inp:
253 for line in inp.readlines():
254 data.append([float(x) for x in line.split('\t')[1:]])
255 mat = np.array(data)
256 preb = np.zeros(mat.shape[0], dtype=np.float64)
257 num_preb = ctypes.c_long()
258 data = np.array(mat.reshape(mat.size), copy=False)
259 LIB.LGBM_BoosterPredictForMat(
260 booster2,
261 data.ctypes.data_as(ctypes.POINTER(ctypes.c_void_p)),
262 dtype_float64,
263 mat.shape[0],
264 mat.shape[1],
265 1,
266 1,
267 25,
268 c_str(''),
269 ctypes.byref(num_preb),
270 preb.ctypes.data_as(ctypes.POINTER(ctypes.c_double)))
271 LIB.LGBM_BoosterPredictForFile(
272 booster2,
273 c_str(os.path.join(os.path.dirname(os.path.realpath(__file__)),
274 '../../examples/binary_classification/binary.test')),

Callers

nothing calls this directly

Calls 7

load_from_matFunction · 0.85
free_datasetFunction · 0.85
joinMethod · 0.80
arrayMethod · 0.80
readlinesMethod · 0.80
appendMethod · 0.80
c_strFunction · 0.70

Tested by

no test coverage detected