lightgbm_R.h 15.9 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
10
11
12
13

#define R_NO_REMAP
#define R_USE_C99_IN_CXX
#include <Rinternals.h>

14
#include "R_object_helper.h"
Guolin Ke's avatar
Guolin Ke committed
15
16
17

/*!
* \brief get string message of the last error
18
* \return err_msg string with error information
Guolin Ke's avatar
Guolin Ke committed
19
*/
20
LIGHTGBM_C_EXPORT SEXP LGBM_GetLastError_R();
Guolin Ke's avatar
Guolin Ke committed
21
22
23
24

// --- start Dataset interface

/*!
25
* \brief load Dataset from file like the command_line LightGBM does
Guolin Ke's avatar
Guolin Ke committed
26
27
* \param filename the name of the file
* \param parameters additional parameters
28
29
30
* \param reference used to align bin mapper with other Dataset, nullptr means not used
* \param out created Dataset
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
31
*/
32
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromFile_R(
33
34
  SEXP filename,
  SEXP parameters,
Guolin Ke's avatar
Guolin Ke committed
35
  LGBM_SE reference,
36
  LGBM_SE out
37
);
Guolin Ke's avatar
Guolin Ke committed
38
39

/*!
40
* \brief create a Dataset from Compressed Sparse Column (CSC) format
Guolin Ke's avatar
Guolin Ke committed
41
42
43
* \param indptr pointer to row headers
* \param indices findex
* \param data fvalue
44
* \param num_indptr number of cols in the matrix + 1
Guolin Ke's avatar
Guolin Ke committed
45
46
47
* \param nelem number of nonzero elements in the matrix
* \param num_row number of rows
* \param parameters additional parameters
48
49
50
* \param reference used to align bin mapper with other Dataset, nullptr means not used
* \param out created Dataset
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
51
*/
52
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromCSC_R(
53
54
55
  SEXP indptr,
  SEXP indices,
  SEXP data,
56
57
58
  SEXP num_indptr,
  SEXP nelem,
  SEXP num_row,
59
  SEXP parameters,
Guolin Ke's avatar
Guolin Ke committed
60
  LGBM_SE reference,
61
  LGBM_SE out
62
);
Guolin Ke's avatar
Guolin Ke committed
63
64

/*!
65
66
* \brief create Dataset from dense matrix
* \param data matrix data
67
68
* \param num_row number of rows
* \param num_col number columns
Guolin Ke's avatar
Guolin Ke committed
69
* \param parameters additional parameters
70
71
72
* \param reference used to align bin mapper with other Dataset, nullptr means not used
* \param out created Dataset
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
73
*/
74
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetCreateFromMat_R(
75
  SEXP data,
76
77
  SEXP num_row,
  SEXP num_col,
78
  SEXP parameters,
Guolin Ke's avatar
Guolin Ke committed
79
  LGBM_SE reference,
80
  LGBM_SE out
81
);
Guolin Ke's avatar
Guolin Ke committed
82
83

/*!
84
85
* \brief Create subset of a Dataset
* \param handle handle of full Dataset
Guolin Ke's avatar
Guolin Ke committed
86
87
88
* \param used_row_indices Indices used in subset
* \param len_used_row_indices length of Indices used in subset
* \param parameters additional parameters
89
90
* \param out created Dataset
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
91
*/
92
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetSubset_R(
93
  LGBM_SE handle,
94
  SEXP used_row_indices,
95
  SEXP len_used_row_indices,
96
  SEXP parameters,
97
  LGBM_SE out
98
);
Guolin Ke's avatar
Guolin Ke committed
99
100
101
102
103

/*!
* \brief save feature names to Dataset
* \param handle handle
* \param feature_names feature names
104
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
105
*/
106
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetFeatureNames_R(
107
  LGBM_SE handle,
108
  SEXP feature_names
109
);
Guolin Ke's avatar
Guolin Ke committed
110
111
112
113
114
115
116

/*!
* \brief save feature names to Dataset
* \param handle handle
* \param feature_names feature names
* \return 0 when succeed, -1 when failure happens
*/
117
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFeatureNames_R(
118
  LGBM_SE handle,
119
  SEXP buf_len,
120
  SEXP actual_len,
121
  LGBM_SE feature_names
122
);
Guolin Ke's avatar
Guolin Ke committed
123
124

/*!
125
126
* \brief save Dataset to binary file
* \param handle an instance of Dataset
Guolin Ke's avatar
Guolin Ke committed
127
* \param filename file name
128
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
129
*/
130
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSaveBinary_R(
131
  LGBM_SE handle,
132
  SEXP filename
133
);
Guolin Ke's avatar
Guolin Ke committed
134
135

/*!
136
137
138
* \brief free Dataset
* \param handle an instance of Dataset
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
139
*/
140
141
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetFree_R(
  LGBM_SE handle
142
);
Guolin Ke's avatar
Guolin Ke committed
143
144
145

/*!
* \brief set vector to a content in info
146
*        Note: group and group_id only work for C_API_DTYPE_INT32
Guolin Ke's avatar
Guolin Ke committed
147
*              label and weight only work for C_API_DTYPE_FLOAT32
148
* \param handle an instance of Dataset
Guolin Ke's avatar
Guolin Ke committed
149
150
151
* \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
152
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
153
*/
154
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetSetField_R(
155
  LGBM_SE handle,
156
  SEXP field_name,
157
  SEXP field_data,
158
  SEXP num_element
159
);
Guolin Ke's avatar
Guolin Ke committed
160
161

/*!
162
163
* \brief get size of info vector from Dataset
* \param handle an instance of Dataset
Guolin Ke's avatar
Guolin Ke committed
164
* \param field_name field name
165
166
* \param out size of info vector from Dataset
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
167
*/
168
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFieldSize_R(
169
  LGBM_SE handle,
170
  SEXP field_name,
171
  SEXP out
172
);
Guolin Ke's avatar
Guolin Ke committed
173
174

/*!
175
176
* \brief get info vector from Dataset
* \param handle an instance of Dataset
Guolin Ke's avatar
Guolin Ke committed
177
178
* \param field_name field name
* \param field_data pointer to vector
179
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
180
*/
181
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetField_R(
182
  LGBM_SE handle,
183
  SEXP field_name,
184
  SEXP field_data
185
);
Guolin Ke's avatar
Guolin Ke committed
186

187
/*!
188
189
190
191
192
 * \brief Raise errors for attempts to update Dataset parameters.
 *        Some parameters cannot be updated after construction.
 * \param old_params Current Dataset parameters
 * \param new_params New Dataset parameters
 * \return R NULL value
193
 */
194
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetUpdateParamChecking_R(
195
196
  SEXP old_params,
  SEXP new_params
197
);
198

Guolin Ke's avatar
Guolin Ke committed
199
200
/*!
* \brief get number of data.
201
* \param handle the handle to the Dataset
Guolin Ke's avatar
Guolin Ke committed
202
* \param out The address to hold number of data
203
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
204
*/
205
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumData_R(
206
  LGBM_SE handle,
207
  SEXP out
208
);
Guolin Ke's avatar
Guolin Ke committed
209
210
211

/*!
* \brief get number of features
212
* \param handle the handle to the Dataset
Guolin Ke's avatar
Guolin Ke committed
213
* \param out The output of number of features
214
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
215
*/
216
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetNumFeature_R(
217
  LGBM_SE handle,
218
  SEXP out
219
);
Guolin Ke's avatar
Guolin Ke committed
220
221
222
223

// --- start Booster interfaces

/*!
224
* \brief create a new boosting learner
225
* \param train_data training Dataset
Guolin Ke's avatar
Guolin Ke committed
226
* \param parameters format: 'key1=value1 key2=value2'
227
* \param out handle of created Booster
228
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
229
*/
230
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreate_R(
231
  LGBM_SE train_data,
232
  SEXP parameters,
233
  LGBM_SE out
234
);
Guolin Ke's avatar
Guolin Ke committed
235
236

/*!
237
* \brief free Booster
Guolin Ke's avatar
Guolin Ke committed
238
* \param handle handle to be freed
239
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
240
*/
241
242
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterFree_R(
  LGBM_SE handle
243
);
Guolin Ke's avatar
Guolin Ke committed
244
245

/*!
246
* \brief load an existing Booster from model file
Guolin Ke's avatar
Guolin Ke committed
247
* \param filename filename of model
248
* \param out handle of created Booster
249
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
250
*/
251
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCreateFromModelfile_R(
252
  SEXP filename,
253
  LGBM_SE out
254
);
Guolin Ke's avatar
Guolin Ke committed
255

256
/*!
257
* \brief load an existing Booster from a string
258
259
* \param model_str string containing the model
* \param out handle of created Booster
260
* \return R NULL value
261
*/
262
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterLoadModelFromString_R(
263
  SEXP model_str,
264
  LGBM_SE out
265
);
266

Guolin Ke's avatar
Guolin Ke committed
267
/*!
268
269
270
271
* \brief Merge model in two Boosters to first handle
* \param handle handle primary Booster handle, will merge other handle to this
* \param other_handle secondary Booster handle
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
272
*/
273
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterMerge_R(
274
  LGBM_SE handle,
275
  LGBM_SE other_handle
276
);
Guolin Ke's avatar
Guolin Ke committed
277
278

/*!
279
280
281
282
* \brief Add new validation to Booster
* \param handle Booster handle
* \param valid_data validation Dataset
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
283
*/
284
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterAddValidData_R(
285
  LGBM_SE handle,
286
  LGBM_SE valid_data
287
);
Guolin Ke's avatar
Guolin Ke committed
288
289

/*!
290
291
292
293
* \brief Reset training data for Booster
* \param handle Booster handle
* \param train_data training Dataset
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
294
*/
295
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetTrainingData_R(
296
  LGBM_SE handle,
297
  LGBM_SE train_data
298
);
Guolin Ke's avatar
Guolin Ke committed
299
300

/*!
301
302
* \brief Reset config for current Booster
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
303
* \param parameters format: 'key1=value1 key2=value2'
304
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
305
*/
306
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetParameter_R(
307
  LGBM_SE handle,
308
  SEXP parameters
309
);
Guolin Ke's avatar
Guolin Ke committed
310
311

/*!
312
* \brief Get number of classes
313
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
314
* \param out number of classes
315
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
316
*/
317
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumClasses_R(
318
  LGBM_SE handle,
319
  SEXP out
320
);
Guolin Ke's avatar
Guolin Ke committed
321
322
323

/*!
* \brief update the model in one round
324
325
* \param handle Booster handle
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
326
*/
327
328
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIter_R(
  LGBM_SE handle
329
);
Guolin Ke's avatar
Guolin Ke committed
330
331

/*!
332
* \brief update the model, by directly specifying gradient and second order gradient,
Guolin Ke's avatar
Guolin Ke committed
333
*       this can be used to support customized loss function
334
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
335
336
337
* \param grad gradient statistics
* \param hess second order gradient statistics
* \param len length of grad/hess
338
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
339
*/
340
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterUpdateOneIterCustom_R(
341
  LGBM_SE handle,
342
343
  SEXP grad,
  SEXP hess,
344
  SEXP len
345
);
Guolin Ke's avatar
Guolin Ke committed
346
347
348

/*!
* \brief Rollback one iteration
349
350
* \param handle Booster handle
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
351
*/
352
353
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterRollbackOneIter_R(
  LGBM_SE handle
354
);
Guolin Ke's avatar
Guolin Ke committed
355
356
357

/*!
* \brief Get iteration of current boosting rounds
358
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
359
* \param out iteration of boosting rounds
360
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
361
*/
362
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetCurrentIteration_R(
363
  LGBM_SE handle,
364
  SEXP out
365
);
Guolin Ke's avatar
Guolin Ke committed
366

367
368
/*!
* \brief Get model upper bound value.
369
* \param handle Handle of Booster
370
* \param[out] out_results Result pointing to max value
371
* \return R NULL value
372
*/
373
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetUpperBoundValue_R(
374
    LGBM_SE handle,
375
    SEXP out_result
376
377
378
379
);

/*!
* \brief Get model lower bound value.
380
* \param handle Handle of Booster
381
* \param[out] out_results Result pointing to min value
382
* \return R NULL value
383
*/
384
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetLowerBoundValue_R(
385
    LGBM_SE handle,
386
    SEXP out_result
387
388
);

Guolin Ke's avatar
Guolin Ke committed
389
390
391
392
393
/*!
* \brief Get Name of eval
* \param eval_names eval names
* \return 0 when succeed, -1 when failure happens
*/
394
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEvalNames_R(
395
  LGBM_SE handle,
396
  SEXP buf_len,
397
  SEXP actual_len,
398
  LGBM_SE eval_names
399
);
Guolin Ke's avatar
Guolin Ke committed
400
401
402

/*!
* \brief get evaluation for training data and validation data
403
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
404
* \param data_idx 0:training data, 1: 1st valid data, 2:2nd valid data ...
405
406
* \param out_result float array containing result
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
407
*/
408
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEval_R(
409
  LGBM_SE handle,
410
  SEXP data_idx,
411
  SEXP out_result
412
);
Guolin Ke's avatar
Guolin Ke committed
413
414
415

/*!
* \brief Get number of prediction for training data and validation data
416
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
417
418
* \param data_idx 0:training data, 1: 1st valid data, 2:2nd valid data ...
* \param out size of predict
419
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
420
*/
421
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumPredict_R(
422
  LGBM_SE handle,
423
  SEXP data_idx,
424
  SEXP out
425
);
Guolin Ke's avatar
Guolin Ke committed
426
427

/*!
428
429
* \brief Get prediction for training data and validation data.
*        This can be used to support customized eval function
430
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
431
432
* \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
433
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
434
*/
435
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetPredict_R(
436
  LGBM_SE handle,
437
  SEXP data_idx,
438
  SEXP out_result
439
);
Guolin Ke's avatar
Guolin Ke committed
440
441
442

/*!
* \brief make prediction for file
443
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
444
445
* \param data_filename filename of data file
* \param data_has_header data file has header or not
446
447
448
449
450
451
* \param is_rawscore 1 to get raw predictions, before transformations like
*                    converting to probabilities, 0 otherwise
* \param is_leafidx 1 to get record of which leaf in each tree
*                   observations fell into, 0 otherwise
* \param is_predcontrib 1 to get feature contributions, 0 otherwise
* \param start_iteration Start index of the iteration to predict
Guolin Ke's avatar
Guolin Ke committed
452
* \param num_iteration number of iteration for prediction, <= 0 means no limit
453
454
455
* \param parameter additional parameters
* \param result_filename filename of file to write predictions to
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
456
*/
457
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForFile_R(
458
  LGBM_SE handle,
459
  SEXP data_filename,
460
461
462
463
464
465
  SEXP data_has_header,
  SEXP is_rawscore,
  SEXP is_leafidx,
  SEXP is_predcontrib,
  SEXP start_iteration,
  SEXP num_iteration,
466
467
  SEXP parameter,
  SEXP result_filename
468
);
Guolin Ke's avatar
Guolin Ke committed
469
470
471

/*!
* \brief Get number of prediction
472
473
474
475
476
477
478
479
* \param handle Booster handle
* \param num_row number of rows in input
* \param is_rawscore 1 to get raw predictions, before transformations like
*                    converting to probabilities, 0 otherwise
* \param is_leafidx 1 to get record of which leaf in each tree
*                   observations fell into, 0 otherwise
* \param is_predcontrib 1 to get feature contributions, 0 otherwise
* \param start_iteration Start index of the iteration to predict
Guolin Ke's avatar
Guolin Ke committed
480
* \param num_iteration number of iteration for prediction, <= 0 means no limit
481
* \param out_len length of prediction
482
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
483
*/
484
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCalcNumPredict_R(
485
  LGBM_SE handle,
486
487
488
489
490
491
  SEXP num_row,
  SEXP is_rawscore,
  SEXP is_leafidx,
  SEXP is_predcontrib,
  SEXP start_iteration,
  SEXP num_iteration,
492
  SEXP out_len
493
);
Guolin Ke's avatar
Guolin Ke committed
494
495

/*!
496
* \brief make prediction for a new Dataset
Guolin Ke's avatar
Guolin Ke committed
497
*        Note:  should pre-allocate memory for out_result,
498
*               for normal and raw score: its length is equal to num_class * num_data
Guolin Ke's avatar
Guolin Ke committed
499
*               for leaf index, its length is equal to num_class * num_data * num_iteration
500
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
501
502
503
* \param indptr pointer to row headers
* \param indices findex
* \param data fvalue
504
* \param num_indptr number of cols in the matrix + 1
505
* \param nelem number of non-zero elements in the matrix
Guolin Ke's avatar
Guolin Ke committed
506
* \param num_row number of rows
507
508
509
510
511
512
* \param is_rawscore 1 to get raw predictions, before transformations like
*                    converting to probabilities, 0 otherwise
* \param is_leafidx 1 to get record of which leaf in each tree
*                   observations fell into, 0 otherwise
* \param is_predcontrib 1 to get feature contributions, 0 otherwise
* \param start_iteration Start index of the iteration to predict
Guolin Ke's avatar
Guolin Ke committed
513
* \param num_iteration number of iteration for prediction, <= 0 means no limit
514
515
516
* \param parameter additional parameters
* \param out_result prediction result
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
517
*/
518
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForCSC_R(
519
  LGBM_SE handle,
520
521
522
  SEXP indptr,
  SEXP indices,
  SEXP data,
523
524
525
526
527
528
529
530
  SEXP num_indptr,
  SEXP nelem,
  SEXP num_row,
  SEXP is_rawscore,
  SEXP is_leafidx,
  SEXP is_predcontrib,
  SEXP start_iteration,
  SEXP num_iteration,
531
  SEXP parameter,
532
  SEXP out_result
533
);
Guolin Ke's avatar
Guolin Ke committed
534
535

/*!
536
* \brief make prediction for a new Dataset
Guolin Ke's avatar
Guolin Ke committed
537
*        Note:  should pre-allocate memory for out_result,
538
*               for normal and raw score: its length is equal to num_class * num_data
Guolin Ke's avatar
Guolin Ke committed
539
*               for leaf index, its length is equal to num_class * num_data * num_iteration
540
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
541
* \param data pointer to the data space
542
543
* \param num_row number of rows
* \param num_col number columns
544
545
546
547
548
549
* \param is_rawscore 1 to get raw predictions, before transformations like
*                    converting to probabilities, 0 otherwise
* \param is_leafidx 1 to get record of which leaf in each tree
*                   observations fell into, 0 otherwise
* \param is_predcontrib 1 to get feature contributions, 0 otherwise
* \param start_iteration Start index of the iteration to predict
Guolin Ke's avatar
Guolin Ke committed
550
* \param num_iteration number of iteration for prediction, <= 0 means no limit
551
552
553
* \param parameter additional parameters
* \param out_result prediction result
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
554
*/
555
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForMat_R(
556
  LGBM_SE handle,
557
  SEXP data,
558
559
560
561
562
563
564
  SEXP num_row,
  SEXP num_col,
  SEXP is_rawscore,
  SEXP is_leafidx,
  SEXP is_predcontrib,
  SEXP start_iteration,
  SEXP num_iteration,
565
  SEXP parameter,
566
  SEXP out_result
567
);
Guolin Ke's avatar
Guolin Ke committed
568
569
570

/*!
* \brief save model into file
571
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
572
* \param num_iteration, <= 0 means save all
573
* \param feature_importance_type type of feature importance, 0: split, 1: gain
Guolin Ke's avatar
Guolin Ke committed
574
* \param filename file name
575
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
576
*/
577
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModel_R(
578
  LGBM_SE handle,
579
580
  SEXP num_iteration,
  SEXP feature_importance_type,
581
  SEXP filename
582
);
Guolin Ke's avatar
Guolin Ke committed
583

584
585
586
587
588
589
590
/*!
* \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
*/
591
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModelToString_R(
592
  LGBM_SE handle,
593
594
595
  SEXP num_iteration,
  SEXP feature_importance_type,
  SEXP buffer_len,
596
  SEXP actual_len,
597
  LGBM_SE out_str
598
);
599

Guolin Ke's avatar
Guolin Ke committed
600
601
602
603
604
605
606
/*!
* \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
*/
607
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterDumpModel_R(
608
  LGBM_SE handle,
609
610
611
  SEXP num_iteration,
  SEXP feature_importance_type,
  SEXP buffer_len,
612
  SEXP actual_len,
613
  LGBM_SE out_str
614
);
Guolin Ke's avatar
Guolin Ke committed
615

616
#endif  // LIGHTGBM_R_H_