README.md 1.84 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
8
9
10
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.

You can use a command prompt to install via command line:

Guolin Ke's avatar
Guolin Ke committed
11
12
13
```
cd R-package
R CMD INSTALL --build  .
Guolin Ke's avatar
Guolin Ke committed
14
15
```

16
17
18
19
20
21
You can also install directly from R using the repository with `devtools`:

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

22
23
If want to build the self-contained R package, you can run ```unix_build_package.sh```(for UNIX) or ```win_build_package.cmd ```(for Windows). Then use ```R CMD INSTALL lightgbm_0.1.tar.gz``` to install.

24
25
26
27
28
29
30
31
32
33
34

You can check quickly if your LightGBM R package is working by running the following:

```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)
```
Guolin Ke's avatar
Guolin Ke committed
35
36
37
38
39
40
### OSX installation 

The default installation cannot successfully in OSX due to clang in OSX doesn't support openmp.
You can use following scirpts to change default compiler to gcc, then complie LightGBM R-package:
```
brew install gcc --without-multilib
41
mkdir -p ~/.R
Guolin Ke's avatar
Guolin Ke committed
42
touch ~/.R/Makevars
43
cat <<EOF >>~/.R/Makevars
Guolin Ke's avatar
Guolin Ke committed
44
45
46
C=gcc-6
CXX=g++-6
CXX1X=g++-6
47
48
LDFLAGS=-L/usr/local/Cellar/gcc/6.3.0/lib
CPPFLAGS=-I/usr/local/Cellar/gcc/6.3.0/include
Guolin Ke's avatar
Guolin Ke committed
49
50
51
52
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FCFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp
53
EOF
Guolin Ke's avatar
Guolin Ke committed
54
```
55
Note: for ``LDFLAGS=-L/usr/local/Cellar/gcc/6.3.0/lib`` and ``CPPFLAGS=-I/usr/local/Cellar/gcc/6.3.0/include``, you may need to change ``6.3.0`` to your gcc version. 
Guolin Ke's avatar
Guolin Ke committed
56

Guolin Ke's avatar
Guolin Ke committed
57
58

Examples
59
------------
Guolin Ke's avatar
Guolin Ke committed
60

61
* Please visit [demo](demo).