Skip to content

Commit

Permalink
Merge branch 'master' into r/msvc-support
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed May 1, 2020
2 parents 5f156a3 + 7076cb8 commit 45a7636
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 61 deletions.
55 changes: 1 addition & 54 deletions R-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Installation

You need to install git and [CMake](https://cmake.org/) first.

Note: 32-bit R/Rtools is not supported.
Note: 32-bit (i386) R/Rtools is currently not supported.

#### Windows Preparation

Expand All @@ -26,8 +26,6 @@ The default compiler is Visual Studio (or [VS Build Tools](https://visualstudio.

To force the usage of Rtools / MinGW, you can set `use_mingw` to `TRUE` in `R-package/src/install.libs.R`.

For users who wants to install online with GPU or want to choose a specific compiler, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)).

**Warning for Windows users**: it is recommended to use *Visual Studio* for its better multi-threading efficiency in Windows for many core systems. For very simple systems (dual core computers or worse), MinGW64 is recommended for maximum performance. If you do not know what to choose, it is recommended to use [Visual Studio](https://visualstudio.microsoft.com/downloads/), the default compiler. **Do not try using MinGW in Windows on many core systems. It may result in 10x slower results than Visual Studio.**

#### Mac OS Preparation
Expand Down Expand Up @@ -70,57 +68,6 @@ params <- list(objective="regression", metric="l2")
model <- lgb.cv(params, dtrain, 10, nfold=5, min_data=1, learning_rate=1, early_stopping_rounds=10)
```

Installation with Precompiled dll/lib from R Using GitHub
---------------------------------------------------------

You can install LightGBM R-package from GitHub with devtools thanks to a helper package for LightGBM.

### Prerequisites

You will need:

* Precompiled LightGBM dll/lib
* MinGW / Visual Studio / gcc (depending on your OS and your needs) with make in PATH environment variable
* git in PATH environment variable
* [CMake](https://cmake.org/) in PATH environment variable
* [lgbdl](https://github.com/Laurae2/lgbdl/) R-package, which can be installed using `devtools::install_github("Laurae2/lgbdl")`
* [Rtools](https://cran.r-project.org/bin/windows/Rtools/) if using Windows

In addition, if you are using a Visual Studio precompiled DLL, assuming you do not have Visual Studio installed (if you have it installed, ignore the warnings below):

* Visual Studio 2015/2017/2019 precompiled DLL: download and install Visual Studio Runtime for [2015](https://www.microsoft.com/en-us/download/details.aspx?id=52685)/[2017](https://aka.ms/vs/15/release/vc_redist.x64.exe)/[2019](https://aka.ms/vs/16/release/vc_redist.x64.exe) (you will get an error about MSVCP140.dll missing otherwise)

Once you have all this setup, you can use `lgb.dl` from `lgbdl` package to install LightGBM from repository.

For instance, you can install the R-package from LightGBM master commit of GitHub with Visual Studio using the following from R:

```r
lgb.dl(commit = "master",
compiler = "vs",
repo = "https://github.com/microsoft/LightGBM")
```

You may also install using a precompiled dll/lib using the following from R:

```r
lgb.dl(commit = "master",
libdll = "C:\\LightGBM\\windows\\x64\\DLL\\lib_lightgbm.dll", # YOUR PRECOMPILED DLL
repo = "https://github.com/microsoft/LightGBM")
```

You may also install online using a LightGBM with proper GPU support using Visual Studio (as an example here) using the following from R:

```r
lgb.dl(commit = "master",
compiler = "vs", # Remove this for MinGW + GPU installation
repo = "https://github.com/microsoft/LightGBM",
use_gpu = TRUE)
```

For more details about options, please check [Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/) R-package.

You may also read [Microsoft/LightGBM#912](https://github.com/microsoft/LightGBM/issues/912#issuecomment-329496254) for a visual example for LightGBM installation in Windows with Visual Studio.

Examples
--------

Expand Down
10 changes: 5 additions & 5 deletions src/objective/rank_objective.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class RankXENDCG : public RankingObjective {
double sum_l1 = 0.0f;
for (data_size_t i = 0; i < cnt; ++i) {
l1s[i] = -l1s[i] / sum_labels + rho[i];
sum_l1 += l1s[i];
sum_l1 += l1s[i] / (1. - rho[i]);
}
if (cnt <= 1) {
// when cnt <= 1, the l2 and l3 are zeros
Expand All @@ -336,13 +336,13 @@ class RankXENDCG : public RankingObjective {
std::vector<double> l2s(cnt, 0.0);
double sum_l2 = 0.0;
for (data_size_t i = 0; i < cnt; ++i) {
l2s[i] = (sum_l1 - l1s[i]) / (1 - rho[i]);
sum_l2 += l2s[i];
l2s[i] = sum_l1 - (l1s[i] / (1. - rho[i]));
sum_l2 += l2s[i] * rho[i] / (1. - rho[i]);
}
for (data_size_t i = 0; i < cnt; ++i) {
auto l3 = (sum_l2 - l2s[i]) / (1 - rho[i]);
auto l3 = sum_l2 - (l2s[i] * rho[i] / (1. - rho[i]));
lambdas[i] = static_cast<score_t>(l1s[i] + rho[i] * l2s[i] +
rho[i] * rho[i] * l3);
rho[i] * l3);
hessians[i] = static_cast<score_t>(rho[i] * (1.0 - rho[i]));
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/python_package_test/test_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def test_xendcg(self):
eval_metric='ndcg',
callbacks=[lgb.reset_parameter(learning_rate=lambda x: max(0.01, 0.1 - 0.01 * x))])
self.assertLessEqual(gbm.best_iteration_, 24)
self.assertGreater(gbm.best_score_['valid_0']['ndcg@1'], 0.6382)
self.assertGreater(gbm.best_score_['valid_0']['ndcg@3'], 0.6319)
self.assertGreater(gbm.best_score_['valid_0']['ndcg@1'], 0.6211)
self.assertGreater(gbm.best_score_['valid_0']['ndcg@3'], 0.6253)

def test_regression_with_custom_objective(self):
X, y = load_boston(True)
Expand Down

0 comments on commit 45a7636

Please sign in to comment.