README.md 3.15 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
5
LightGBM R Package
==================

Installation
------------
Guolin Ke's avatar
Guolin Ke committed
6

7
### Preparation
Laurae's avatar
Laurae committed
8
You need to install git and [cmake](https://cmake.org/) first.
9

Laurae's avatar
Laurae committed
10
The default compiler is Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) in Windows. You also can use Rtools (default) or [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) to compile by setting `use_mingw` to `TRUE` in `R-package/src/install.libs.R`.
11

Laurae's avatar
Laurae committed
12
13
14
15
16
It is recommended to use *Visual Studio* for its better multi-threading efficency in Windows for many core systems. For simple systems (like laptops or small desktops), MinGW64 is recommended.

For Mac OS X users, gcc with OpenMP support must be installed first. Refer to [wiki](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#osx) for installing gcc with OpenMP support.

To avoid critical package issues if you are using R 3.4.0 (not the patched/devel version), it is recommended to install once the LightGBM R package, even if it is an old version: `devtools::install_github("Microsoft/LightGBM@v1", subdir = "R-package")`. Make sure you have the correct permissions to install the package.
17

18
### Install
Laurae's avatar
Laurae committed
19
Install LightGBM R-package with the following command:
20

Laurae's avatar
Laurae committed
21
```sh
22
23
24
git clone --recursive https://github.com/Microsoft/LightGBM
cd LightGBM/R-package
R CMD INSTALL --build .
Guolin Ke's avatar
Guolin Ke committed
25
```
Laurae's avatar
Laurae committed
26
27
28
29

Or build a self-contained R package which can be installed afterwards:

```sh
30
31
32
git clone --recursive https://github.com/Microsoft/LightGBM
cd LightGBM/R-package
Rscript build_package.R
Laurae's avatar
Laurae committed
33
R CMD INSTALL lightgbm_0.2.tar.gz
34
``` 
Guolin Ke's avatar
Guolin Ke committed
35

36
37
Windows users may need to run with administrator rights (either R or the command prompt, depending on the way you are installing this package). Rtools must be installed for Windows. Linux users might require the appropriate user write permissions for packages.

Laurae's avatar
Laurae committed
38
Set `use_gpu` to `TRUE` in `R-package/src/install.libs.R` to enable the build with GPU support. You will need to install Boost and OpenCL first: details for installation can be found in [gpu-support](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#with-gpu-support).
39
40

You can also install directly from R using the repository with `devtools`:
41

42
```r
43
devtools::install_github("Microsoft/LightGBM", subdir = "R-package")
44
```
45

46
When your package installation is done, you can check quickly if your LightGBM R package is working by running the following:
47
48
49
50
51
52
53
54
55

```r
library(lightgbm)
data(agaricus.train, package='lightgbm')
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label=train$label)
params <- list(objective="regression", metric="l2")
model <- lgb.cv(params, dtrain, 10, nfold=5, min_data=1, learning_rate=1, early_stopping_rounds=10)
```
56

Guolin Ke's avatar
Guolin Ke committed
57
Examples
58
------------
Guolin Ke's avatar
Guolin Ke committed
59

60
61
62
63
64
65
66
67
68
Please visit [demo](demo):

* [Basic walkthrough of wrappers](demo/basic_walkthrough.R)
* [Boosting from existing prediction](demo/boost_from_prediction.R)
* [Early Stopping](demo/early_stopping.R)
* [Cross Validation](demo/cross_validation.R)
* [Multiclass Training/Prediction](demo/multiclass.R)
* [Leaf (in)Stability](demo/leaf_stability.R)
* [Weight-Parameter Adjustment Relationship](demo/weight_param.R)