lightgbm_R.h 16.3 KB
Newer Older
1
2
3
4
/*!
 * Copyright (c) 2017 Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See LICENSE file in the project root for license information.
 */
Guolin Ke's avatar
Guolin Ke committed
5
6
7
8
#ifndef LIGHTGBM_R_H_
#define LIGHTGBM_R_H_

#include <LightGBM/c_api.h>
9
#include "R_object_helper.h"
Guolin Ke's avatar
Guolin Ke committed
10
11
12

/*!
* \brief get string message of the last error
13
*  all functions in this file will return 0 on success
14
15
16
*  and -1 when an error occurred
* \return err_msg error information
* \return error information
Guolin Ke's avatar
Guolin Ke committed
17
*/
18
19
20
21
22
LIGHTGBM_C_EXPORT LGBM_SE LGBM_GetLastError_R(
    LGBM_SE buf_len,
    LGBM_SE actual_len,
    LGBM_SE err_msg
);
Guolin Ke's avatar
Guolin Ke committed
23
24
25
26

// --- start Dataset interface

/*!
27
* \brief load data set from file like the command_line LightGBM does
Guolin Ke's avatar
Guolin Ke committed
28
29
* \param filename the name of the file
* \param parameters additional parameters
30
* \param reference used to align bin mapper with other dataset, nullptr means not used
Guolin Ke's avatar
Guolin Ke committed
31
32
33
* \param out created dataset
* \return 0 when succeed, -1 when failure happens
*/
34
35
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromFile_R(
  LGBM_SE filename,
Guolin Ke's avatar
Guolin Ke committed
36
37
38
  LGBM_SE parameters,
  LGBM_SE reference,
  LGBM_SE out,
39
40
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
41
42
43
44
45
46
47
48
49
50

/*!
* \brief create a dataset from CSC format
* \param indptr pointer to row headers
* \param indices findex
* \param data fvalue
* \param nindptr number of cols in the matrix + 1
* \param nelem number of nonzero elements in the matrix
* \param num_row number of rows
* \param parameters additional parameters
51
* \param reference used to align bin mapper with other dataset, nullptr means not used
Guolin Ke's avatar
Guolin Ke committed
52
53
54
* \param out created dataset
* \return 0 when succeed, -1 when failure happens
*/
55
56
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromCSC_R(
  LGBM_SE indptr,
Guolin Ke's avatar
Guolin Ke committed
57
58
59
60
61
62
63
64
  LGBM_SE indices,
  LGBM_SE data,
  LGBM_SE nindptr,
  LGBM_SE nelem,
  LGBM_SE num_row,
  LGBM_SE parameters,
  LGBM_SE reference,
  LGBM_SE out,
65
66
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
67
68
69
70
71
72
73

/*!
* \brief create dataset from dense matrix
* \param data matric data
* \param nrow number of rows
* \param ncol number columns
* \param parameters additional parameters
74
* \param reference used to align bin mapper with other dataset, nullptr means not used
Guolin Ke's avatar
Guolin Ke committed
75
76
77
* \param out created dataset
* \return 0 when succeed, -1 when failure happens
*/
78
79
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetCreateFromMat_R(
  LGBM_SE data,
Guolin Ke's avatar
Guolin Ke committed
80
81
82
83
84
  LGBM_SE nrow,
  LGBM_SE ncol,
  LGBM_SE parameters,
  LGBM_SE reference,
  LGBM_SE out,
85
86
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
87
88
89
90
91
92
93
94
95
96

/*!
* \brief Create subset of a data
* \param handle handle of full dataset
* \param used_row_indices Indices used in subset
* \param len_used_row_indices length of Indices used in subset
* \param parameters additional parameters
* \param out created dataset
* \return 0 when succeed, -1 when failure happens
*/
97
98
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetSubset_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
99
100
101
102
  LGBM_SE used_row_indices,
  LGBM_SE len_used_row_indices,
  LGBM_SE parameters,
  LGBM_SE out,
103
104
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
105
106
107
108
109
110
111

/*!
* \brief save feature names to Dataset
* \param handle handle
* \param feature_names feature names
* \return 0 when succeed, -1 when failure happens
*/
112
113
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetFeatureNames_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
114
  LGBM_SE feature_names,
115
116
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
117
118
119
120
121
122
123

/*!
* \brief save feature names to Dataset
* \param handle handle
* \param feature_names feature names
* \return 0 when succeed, -1 when failure happens
*/
124
125
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFeatureNames_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
126
127
128
  LGBM_SE buf_len,
  LGBM_SE actual_len,
  LGBM_SE feature_names,
129
130
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
131
132

/*!
133
* \brief save dataset to binary file
134
* \param handle an instance of dataset
Guolin Ke's avatar
Guolin Ke committed
135
136
137
* \param filename file name
* \return 0 when succeed, -1 when failure happens
*/
138
139
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSaveBinary_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
140
  LGBM_SE filename,
141
142
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
143
144
145

/*!
* \brief free dataset
146
* \param handle an instance of dataset
Guolin Ke's avatar
Guolin Ke committed
147
148
* \return 0 when succeed, -1 when failure happens
*/
149
150
151
152
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetFree_R(
  LGBM_SE handle,
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
153
154
155

/*!
* \brief set vector to a content in info
156
*        Note: group and group_id only work for C_API_DTYPE_INT32
Guolin Ke's avatar
Guolin Ke committed
157
*              label and weight only work for C_API_DTYPE_FLOAT32
158
* \param handle an instance of dataset
Guolin Ke's avatar
Guolin Ke committed
159
160
161
162
163
* \param field_name field name, can be label, weight, group, group_id
* \param field_data pointer to vector
* \param num_element number of element in field_data
* \return 0 when succeed, -1 when failure happens
*/
164
165
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetSetField_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
166
167
168
  LGBM_SE field_name,
  LGBM_SE field_data,
  LGBM_SE num_element,
169
170
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
171
172
173

/*!
* \brief get size of info vector from dataset
174
* \param handle an instance of dataset
Guolin Ke's avatar
Guolin Ke committed
175
176
177
178
* \param field_name field name
* \param out size of info vector from dataset
* \return 0 when succeed, -1 when failure happens
*/
179
180
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetFieldSize_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
181
182
  LGBM_SE field_name,
  LGBM_SE out,
183
184
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
185
186
187

/*!
* \brief get info vector from dataset
188
* \param handle an instance of dataset
Guolin Ke's avatar
Guolin Ke committed
189
190
191
192
* \param field_name field name
* \param field_data pointer to vector
* \return 0 when succeed, -1 when failure happens
*/
193
194
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetField_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
195
196
  LGBM_SE field_name,
  LGBM_SE field_data,
197
198
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
199

200
/*!
201
202
203
204
205
 * \brief Raise errors for attempts to update dataset parameters
 * \param old_params Current dataset parameters
 * \param new_params New dataset parameters
 * \return 0 when succeed, -1 when failure happens
 */
206
207
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetUpdateParamChecking_R(
  LGBM_SE old_params,
208
  LGBM_SE new_params,
209
210
  LGBM_SE call_state
);
211

Guolin Ke's avatar
Guolin Ke committed
212
213
214
215
216
217
/*!
* \brief get number of data.
* \param handle the handle to the dataset
* \param out The address to hold number of data
* \return 0 when succeed, -1 when failure happens
*/
218
219
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumData_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
220
  LGBM_SE out,
221
222
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
223
224
225
226
227
228
229

/*!
* \brief get number of features
* \param handle the handle to the dataset
* \param out The output of number of features
* \return 0 when succeed, -1 when failure happens
*/
230
231
LIGHTGBM_C_EXPORT LGBM_SE LGBM_DatasetGetNumFeature_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
232
  LGBM_SE out,
233
234
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
235
236
237
238

// --- start Booster interfaces

/*!
239
* \brief create a new boosting learner
Guolin Ke's avatar
Guolin Ke committed
240
241
* \param train_data training data set
* \param parameters format: 'key1=value1 key2=value2'
242
* \param out handle of created Booster
Guolin Ke's avatar
Guolin Ke committed
243
244
* \return 0 when succeed, -1 when failure happens
*/
245
246
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreate_R(
  LGBM_SE train_data,
Guolin Ke's avatar
Guolin Ke committed
247
248
  LGBM_SE parameters,
  LGBM_SE out,
249
250
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
251
252
253
254
255
256

/*!
* \brief free obj in handle
* \param handle handle to be freed
* \return 0 when succeed, -1 when failure happens
*/
257
258
259
260
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterFree_R(
  LGBM_SE handle,
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
261
262
263
264

/*!
* \brief load an existing boosting from model file
* \param filename filename of model
265
* \param out handle of created Booster
Guolin Ke's avatar
Guolin Ke committed
266
267
* \return 0 when succeed, -1 when failure happens
*/
268
269
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCreateFromModelfile_R(
  LGBM_SE filename,
Guolin Ke's avatar
Guolin Ke committed
270
  LGBM_SE out,
271
272
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
273

274
275
276
277
278
279
/*!
* \brief load an existing boosting from model_str
* \param model_str string containing the model
* \param out handle of created Booster
* \return 0 when succeed, -1 when failure happens
*/
280
281
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterLoadModelFromString_R(
  LGBM_SE model_str,
282
  LGBM_SE out,
283
284
  LGBM_SE call_state
);
285

Guolin Ke's avatar
Guolin Ke committed
286
/*!
287
* \brief Merge model in two boosters to first handle
Guolin Ke's avatar
Guolin Ke committed
288
289
290
291
* \param handle handle, will merge other handle to this
* \param other_handle
* \return 0 when succeed, -1 when failure happens
*/
292
293
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterMerge_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
294
  LGBM_SE other_handle,
295
296
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
297
298
299
300
301
302
303

/*!
* \brief Add new validation to booster
* \param handle handle
* \param valid_data validation data set
* \return 0 when succeed, -1 when failure happens
*/
304
305
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterAddValidData_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
306
  LGBM_SE valid_data,
307
308
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
309
310
311
312
313
314
315

/*!
* \brief Reset training data for booster
* \param handle handle
* \param train_data training data set
* \return 0 when succeed, -1 when failure happens
*/
316
317
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetTrainingData_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
318
  LGBM_SE train_data,
319
320
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
321
322
323
324
325
326
327

/*!
* \brief Reset config for current booster
* \param handle handle
* \param parameters format: 'key1=value1 key2=value2'
* \return 0 when succeed, -1 when failure happens
*/
328
329
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterResetParameter_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
330
  LGBM_SE parameters,
331
332
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
333
334

/*!
335
* \brief Get number of classes
Guolin Ke's avatar
Guolin Ke committed
336
337
338
339
* \param handle handle
* \param out number of classes
* \return 0 when succeed, -1 when failure happens
*/
340
341
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumClasses_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
342
  LGBM_SE out,
343
344
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
345
346
347
348
349
350

/*!
* \brief update the model in one round
* \param handle handle
* \return 0 when succeed, -1 when failure happens
*/
351
352
353
354
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIter_R(
  LGBM_SE handle,
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
355
356
357
358
359
360
361
362
363
364

/*!
* \brief update the model, by directly specify gradient and second order gradient,
*       this can be used to support customized loss function
* \param handle handle
* \param grad gradient statistics
* \param hess second order gradient statistics
* \param len length of grad/hess
* \return 0 when succeed, -1 when failure happens
*/
365
366
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterUpdateOneIterCustom_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
367
368
369
  LGBM_SE grad,
  LGBM_SE hess,
  LGBM_SE len,
370
371
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
372
373
374
375
376
377

/*!
* \brief Rollback one iteration
* \param handle handle
* \return 0 when succeed, -1 when failure happens
*/
378
379
380
381
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterRollbackOneIter_R(
  LGBM_SE handle,
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
382
383
384
385
386
387

/*!
* \brief Get iteration of current boosting rounds
* \param out iteration of boosting rounds
* \return 0 when succeed, -1 when failure happens
*/
388
389
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetCurrentIteration_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
390
  LGBM_SE out,
391
392
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
393

394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*!
* \brief Get model upper bound value.
* \param handle Handle of booster
* \param[out] out_results Result pointing to max value
* \return 0 when succeed, -1 when failure happens
*/
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetUpperBoundValue_R(
    LGBM_SE handle,
    LGBM_SE out_result,
    LGBM_SE call_state
);

/*!
* \brief Get model lower bound value.
* \param handle Handle of booster
* \param[out] out_results Result pointing to min value
* \return 0 when succeed, -1 when failure happens
*/
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetLowerBoundValue_R(
    LGBM_SE handle,
    LGBM_SE out_result,
    LGBM_SE call_state
);

Guolin Ke's avatar
Guolin Ke committed
418
419
420
421
422
/*!
* \brief Get Name of eval
* \param eval_names eval names
* \return 0 when succeed, -1 when failure happens
*/
423
424
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEvalNames_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
425
426
427
  LGBM_SE buf_len,
  LGBM_SE actual_len,
  LGBM_SE eval_names,
428
429
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
430
431
432
433
434

/*!
* \brief get evaluation for training data and validation data
* \param handle handle
* \param data_idx 0:training data, 1: 1st valid data, 2:2nd valid data ...
435
* \param out_result float array contains result
Guolin Ke's avatar
Guolin Ke committed
436
437
* \return 0 when succeed, -1 when failure happens
*/
438
439
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetEval_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
440
441
  LGBM_SE data_idx,
  LGBM_SE out_result,
442
443
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
444
445
446
447
448
449
450
451

/*!
* \brief Get number of prediction for training data and validation data
* \param handle handle
* \param data_idx 0:training data, 1: 1st valid data, 2:2nd valid data ...
* \param out size of predict
* \return 0 when succeed, -1 when failure happens
*/
452
453
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetNumPredict_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
454
455
  LGBM_SE data_idx,
  LGBM_SE out,
456
457
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
458
459

/*!
460
461
* \brief Get prediction for training data and validation data.
*        This can be used to support customized eval function
Guolin Ke's avatar
Guolin Ke committed
462
463
464
465
466
* \param handle handle
* \param data_idx 0:training data, 1: 1st valid data, 2:2nd valid data ...
* \param out_result, used to store predict result, should pre-allocate memory
* \return 0 when succeed, -1 when failure happens
*/
467
468
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterGetPredict_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
469
470
  LGBM_SE data_idx,
  LGBM_SE out_result,
471
472
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
473
474
475
476
477
478
479
480
481
482
483
484

/*!
* \brief make prediction for file
* \param handle handle
* \param data_filename filename of data file
* \param data_has_header data file has header or not
* \param is_rawscore
* \param is_leafidx
* \param num_iteration number of iteration for prediction, <= 0 means no limit
* \return 0 when succeed, -1 when failure happens
* \return 0 when succeed, -1 when failure happens
*/
485
486
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForFile_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
487
488
489
490
  LGBM_SE data_filename,
  LGBM_SE data_has_header,
  LGBM_SE is_rawscore,
  LGBM_SE is_leafidx,
491
  LGBM_SE is_predcontrib,
492
  LGBM_SE start_iteration,
Guolin Ke's avatar
Guolin Ke committed
493
  LGBM_SE num_iteration,
494
  LGBM_SE parameter,
Guolin Ke's avatar
Guolin Ke committed
495
  LGBM_SE result_filename,
496
497
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
498
499
500
501
502
503
504
505

/*!
* \brief Get number of prediction
* \param handle handle
* \param num_row
* \param is_rawscore
* \param is_leafidx
* \param num_iteration number of iteration for prediction, <= 0 means no limit
506
* \param out_len length of prediction
Guolin Ke's avatar
Guolin Ke committed
507
508
* \return 0 when succeed, -1 when failure happens
*/
509
510
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterCalcNumPredict_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
511
512
513
  LGBM_SE num_row,
  LGBM_SE is_rawscore,
  LGBM_SE is_leafidx,
514
  LGBM_SE is_predcontrib,
515
  LGBM_SE start_iteration,
Guolin Ke's avatar
Guolin Ke committed
516
517
  LGBM_SE num_iteration,
  LGBM_SE out_len,
518
519
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
520
521

/*!
522
* \brief make prediction for a new data set
Guolin Ke's avatar
Guolin Ke committed
523
*        Note:  should pre-allocate memory for out_result,
524
*               for normal and raw score: its length is equal to num_class * num_data
Guolin Ke's avatar
Guolin Ke committed
525
526
527
528
529
530
*               for leaf index, its length is equal to num_class * num_data * num_iteration
* \param handle handle
* \param indptr pointer to row headers
* \param indices findex
* \param data fvalue
* \param nindptr number of cols in the matrix + 1
531
* \param nelem number of non-zero elements in the matrix
Guolin Ke's avatar
Guolin Ke committed
532
533
534
535
536
537
538
* \param num_row number of rows
* \param is_rawscore
* \param is_leafidx
* \param num_iteration number of iteration for prediction, <= 0 means no limit
* \param out prediction result
* \return 0 when succeed, -1 when failure happens
*/
539
540
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForCSC_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
541
542
543
544
545
546
547
548
  LGBM_SE indptr,
  LGBM_SE indices,
  LGBM_SE data,
  LGBM_SE nindptr,
  LGBM_SE nelem,
  LGBM_SE num_row,
  LGBM_SE is_rawscore,
  LGBM_SE is_leafidx,
549
  LGBM_SE is_predcontrib,
550
  LGBM_SE start_iteration,
Guolin Ke's avatar
Guolin Ke committed
551
  LGBM_SE num_iteration,
552
  LGBM_SE parameter,
Guolin Ke's avatar
Guolin Ke committed
553
  LGBM_SE out_result,
554
555
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
556
557

/*!
558
* \brief make prediction for a new data set
Guolin Ke's avatar
Guolin Ke committed
559
*        Note:  should pre-allocate memory for out_result,
560
*               for normal and raw score: its length is equal to num_class * num_data
Guolin Ke's avatar
Guolin Ke committed
561
562
563
564
565
566
567
568
569
570
571
*               for leaf index, its length is equal to num_class * num_data * num_iteration
* \param handle handle
* \param data pointer to the data space
* \param nrow number of rows
* \param ncol number columns
* \param is_rawscore
* \param is_leafidx
* \param num_iteration number of iteration for prediction, <= 0 means no limit
* \param out prediction result
* \return 0 when succeed, -1 when failure happens
*/
572
573
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForMat_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
574
575
576
577
578
  LGBM_SE data,
  LGBM_SE nrow,
  LGBM_SE ncol,
  LGBM_SE is_rawscore,
  LGBM_SE is_leafidx,
579
  LGBM_SE is_predcontrib,
580
  LGBM_SE start_iteration,
Guolin Ke's avatar
Guolin Ke committed
581
  LGBM_SE num_iteration,
582
  LGBM_SE parameter,
Guolin Ke's avatar
Guolin Ke committed
583
  LGBM_SE out_result,
584
585
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
586
587
588
589
590
591
592
593

/*!
* \brief save model into file
* \param handle handle
* \param num_iteration, <= 0 means save all
* \param filename file name
* \return 0 when succeed, -1 when failure happens
*/
594
595
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModel_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
596
  LGBM_SE num_iteration,
597
  LGBM_SE feature_importance_type,
Guolin Ke's avatar
Guolin Ke committed
598
  LGBM_SE filename,
599
600
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
601

602
603
604
605
606
607
608
/*!
* \brief create string containing model
* \param handle handle
* \param num_iteration, <= 0 means save all
* \param out_str string of model
* \return 0 when succeed, -1 when failure happens
*/
609
610
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModelToString_R(
  LGBM_SE handle,
611
  LGBM_SE num_iteration,
612
  LGBM_SE feature_importance_type,
613
614
615
  LGBM_SE buffer_len,
  LGBM_SE actual_len,
  LGBM_SE out_str,
616
617
  LGBM_SE call_state
);
618

Guolin Ke's avatar
Guolin Ke committed
619
620
621
622
623
624
625
/*!
* \brief dump model to json
* \param handle handle
* \param num_iteration, <= 0 means save all
* \param out_str json format string of model
* \return 0 when succeed, -1 when failure happens
*/
626
627
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterDumpModel_R(
  LGBM_SE handle,
Guolin Ke's avatar
Guolin Ke committed
628
  LGBM_SE num_iteration,
629
  LGBM_SE feature_importance_type,
Guolin Ke's avatar
Guolin Ke committed
630
631
632
  LGBM_SE buffer_len,
  LGBM_SE actual_len,
  LGBM_SE out_str,
633
634
  LGBM_SE call_state
);
Guolin Ke's avatar
Guolin Ke committed
635

636
#endif  // LIGHTGBM_R_H_