lightgbm_R.h 15.8 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 character vector of feature names
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
* \brief get feature names from Dataset
* \param handle Dataset handle
* \return an R character vector with feature names from the Dataset or NULL if no feature names
Guolin Ke's avatar
Guolin Ke committed
115
*/
116
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetGetFeatureNames_R(
117
  LGBM_SE handle
118
);
Guolin Ke's avatar
Guolin Ke committed
119
120

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

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

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

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

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

183
/*!
184
185
186
187
188
 * \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
189
 */
190
LIGHTGBM_C_EXPORT SEXP LGBM_DatasetUpdateParamChecking_R(
191
192
  SEXP old_params,
  SEXP new_params
193
);
194

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

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

// --- start Booster interfaces

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

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

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

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

Guolin Ke's avatar
Guolin Ke committed
263
/*!
264
265
266
267
* \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
268
*/
269
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterMerge_R(
270
  LGBM_SE handle,
271
  LGBM_SE other_handle
272
);
Guolin Ke's avatar
Guolin Ke committed
273
274

/*!
275
276
277
278
* \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
279
*/
280
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterAddValidData_R(
281
  LGBM_SE handle,
282
  LGBM_SE valid_data
283
);
Guolin Ke's avatar
Guolin Ke committed
284
285

/*!
286
287
288
289
* \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
290
*/
291
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterResetTrainingData_R(
292
  LGBM_SE handle,
293
  LGBM_SE train_data
294
);
Guolin Ke's avatar
Guolin Ke committed
295
296

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

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

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

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

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

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

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

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

Guolin Ke's avatar
Guolin Ke committed
385
/*!
386
387
388
* \brief Get names of eval metrics
* \param handle Handle of booster
* \return R character vector with names of eval metrics
Guolin Ke's avatar
Guolin Ke committed
389
*/
390
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEvalNames_R(
391
  LGBM_SE handle
392
);
Guolin Ke's avatar
Guolin Ke committed
393
394
395

/*!
* \brief get evaluation for training data and validation data
396
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
397
* \param data_idx 0:training data, 1: 1st valid data, 2:2nd valid data ...
398
399
* \param out_result float array containing result
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
400
*/
401
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetEval_R(
402
  LGBM_SE handle,
403
  SEXP data_idx,
404
  SEXP out_result
405
);
Guolin Ke's avatar
Guolin Ke committed
406
407
408

/*!
* \brief Get number of prediction for training data and validation data
409
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
410
411
* \param data_idx 0:training data, 1: 1st valid data, 2:2nd valid data ...
* \param out size of predict
412
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
413
*/
414
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterGetNumPredict_R(
415
  LGBM_SE handle,
416
  SEXP data_idx,
417
  SEXP out
418
);
Guolin Ke's avatar
Guolin Ke committed
419
420

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

/*!
* \brief make prediction for file
436
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
437
438
* \param data_filename filename of data file
* \param data_has_header data file has header or not
439
440
441
442
443
444
* \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
445
* \param num_iteration number of iteration for prediction, <= 0 means no limit
446
447
448
* \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
449
*/
450
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForFile_R(
451
  LGBM_SE handle,
452
  SEXP data_filename,
453
454
455
456
457
458
  SEXP data_has_header,
  SEXP is_rawscore,
  SEXP is_leafidx,
  SEXP is_predcontrib,
  SEXP start_iteration,
  SEXP num_iteration,
459
460
  SEXP parameter,
  SEXP result_filename
461
);
Guolin Ke's avatar
Guolin Ke committed
462
463
464

/*!
* \brief Get number of prediction
465
466
467
468
469
470
471
472
* \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
473
* \param num_iteration number of iteration for prediction, <= 0 means no limit
474
* \param out_len length of prediction
475
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
476
*/
477
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterCalcNumPredict_R(
478
  LGBM_SE handle,
479
480
481
482
483
484
  SEXP num_row,
  SEXP is_rawscore,
  SEXP is_leafidx,
  SEXP is_predcontrib,
  SEXP start_iteration,
  SEXP num_iteration,
485
  SEXP out_len
486
);
Guolin Ke's avatar
Guolin Ke committed
487
488

/*!
489
* \brief make prediction for a new Dataset
Guolin Ke's avatar
Guolin Ke committed
490
*        Note:  should pre-allocate memory for out_result,
491
*               for normal and raw score: its length is equal to num_class * num_data
Guolin Ke's avatar
Guolin Ke committed
492
*               for leaf index, its length is equal to num_class * num_data * num_iteration
493
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
494
495
496
* \param indptr pointer to row headers
* \param indices findex
* \param data fvalue
497
* \param num_indptr number of cols in the matrix + 1
498
* \param nelem number of non-zero elements in the matrix
Guolin Ke's avatar
Guolin Ke committed
499
* \param num_row number of rows
500
501
502
503
504
505
* \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
506
* \param num_iteration number of iteration for prediction, <= 0 means no limit
507
508
509
* \param parameter additional parameters
* \param out_result prediction result
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
510
*/
511
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForCSC_R(
512
  LGBM_SE handle,
513
514
515
  SEXP indptr,
  SEXP indices,
  SEXP data,
516
517
518
519
520
521
522
523
  SEXP num_indptr,
  SEXP nelem,
  SEXP num_row,
  SEXP is_rawscore,
  SEXP is_leafidx,
  SEXP is_predcontrib,
  SEXP start_iteration,
  SEXP num_iteration,
524
  SEXP parameter,
525
  SEXP out_result
526
);
Guolin Ke's avatar
Guolin Ke committed
527
528

/*!
529
* \brief make prediction for a new Dataset
Guolin Ke's avatar
Guolin Ke committed
530
*        Note:  should pre-allocate memory for out_result,
531
*               for normal and raw score: its length is equal to num_class * num_data
Guolin Ke's avatar
Guolin Ke committed
532
*               for leaf index, its length is equal to num_class * num_data * num_iteration
533
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
534
* \param data pointer to the data space
535
536
* \param num_row number of rows
* \param num_col number columns
537
538
539
540
541
542
* \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
543
* \param num_iteration number of iteration for prediction, <= 0 means no limit
544
545
546
* \param parameter additional parameters
* \param out_result prediction result
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
547
*/
548
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterPredictForMat_R(
549
  LGBM_SE handle,
550
  SEXP data,
551
552
553
554
555
556
557
  SEXP num_row,
  SEXP num_col,
  SEXP is_rawscore,
  SEXP is_leafidx,
  SEXP is_predcontrib,
  SEXP start_iteration,
  SEXP num_iteration,
558
  SEXP parameter,
559
  SEXP out_result
560
);
Guolin Ke's avatar
Guolin Ke committed
561
562
563

/*!
* \brief save model into file
564
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
565
* \param num_iteration, <= 0 means save all
566
* \param feature_importance_type type of feature importance, 0: split, 1: gain
Guolin Ke's avatar
Guolin Ke committed
567
* \param filename file name
568
* \return R NULL value
Guolin Ke's avatar
Guolin Ke committed
569
*/
570
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModel_R(
571
  LGBM_SE handle,
572
573
  SEXP num_iteration,
  SEXP feature_importance_type,
574
  SEXP filename
575
);
Guolin Ke's avatar
Guolin Ke committed
576

577
578
/*!
* \brief create string containing model
579
* \param handle Booster handle
580
* \param num_iteration, <= 0 means save all
581
582
* \param feature_importance_type type of feature importance, 0: split, 1: gain
* \return R character vector (length=1) with model string
583
*/
584
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterSaveModelToString_R(
585
  LGBM_SE handle,
586
  SEXP num_iteration,
587
  SEXP feature_importance_type
588
);
589

Guolin Ke's avatar
Guolin Ke committed
590
/*!
591
592
* \brief dump model to JSON
* \param handle Booster handle
Guolin Ke's avatar
Guolin Ke committed
593
* \param num_iteration, <= 0 means save all
594
595
* \param feature_importance_type type of feature importance, 0: split, 1: gain
* \return R character vector (length=1) with model JSON
Guolin Ke's avatar
Guolin Ke committed
596
*/
597
LIGHTGBM_C_EXPORT SEXP LGBM_BoosterDumpModel_R(
598
  LGBM_SE handle,
599
  SEXP num_iteration,
600
  SEXP feature_importance_type
601
);
Guolin Ke's avatar
Guolin Ke committed
602

603
#endif  // LIGHTGBM_R_H_