0-总程序代码在这里
安装细节见下文
1-下载xgboost,配置Cmake
- make folder D:\xgboost
-
create an empty git repository
-
pull from github.com/dmlc/xgboos…
-
Git bash here (D:\r\xgboost) - open a git bash. In it type:
-
git submodule init
-
git submodule update
-
install cmake and add path to the env (automatically, just select the option)
查看电脑中是否有cmake,cmd 中输入以下代码:
如果没有安装,则根据msi 下载链接安装:
= cgold.readthedocs.io/en/latest/f…
= download and install: github.com/Kitware/CMa…
2-build
- In dos, go to folder D:\r\xgboost. In it execute:
mkdir build
cd build
cmake .. -G"Visual Studio 14 2015 Win64"
for VS15: cmake .. -G"Visual Studio 15 2017" -A x64
for VS16: cmake .. -G"Visual Studio 16 2019" -A x64
这边容易出现报错信息:
CMake Error at CMakeLists.txt:3 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
Configuring incomplete, errors occurred!
解决方案:
0. 安装“Visual Studio Installer”
docs.microsoft.com/en-us/visua…
上面网址可下载。
1.检查是否安装 “使用C++的桌面开发”
2.检查是否安装 “Visual Studio 扩展开发”
3.点开“单个组件”检查是否安装了以下组件
4.检查计算机变量,是否有以下这个环境变量。
cmake --build . --config Release
Result:
xgboost.dll is created here: "D:\r\xgboost\lib\xgboost.dll"
3-配置头文件
-
download header file: raw.githubusercontent.com/dmlc/xgboos…
-
save it to "D:\r\xgboost\lib"
-
rename c_api.h to xgboost.h
Result:
xgboost.h is created here: "D:\r\xgboost\lib\xgboost.h"
4-下载wheel 文件,修改 xgboost_install.m 并运行xgboost_train.m
下载wheel 文件
s3-us-west-2.amazonaws.com/xgboost-nig…
上面的网址可以下载
修改xgboost_install.m 中安装文件的位置
In xgboost_test.m and xgboost_train.m, change D:\r\xgboost\lib to the location of xgboost (only if you put it in another directory)
这几步OK后 运行xgboost_install.m xgboost 安装完毕
5-运行测试用例
clc;
clear;
load carsmall;
Xtrain = [Acceleration Cylinders Displacement Horsepower MPG];
ytrain = cellstr(Origin);
ytrain = double(ismember(ytrain,'USA'));
X = Xtrain(1:70,:);
y = ytrain(1:70);
Xtest = Xtrain(size(X,1)+1:end,:);
ytest = ytrain(size(X,1)+1:end);
model_filename = 'xgboost_model.xgb';
model = xgboost_train(X,y,[],999,'AUC',model_filename); %%% model_filename = 'xgboost_model.xgb'
loadmodel = 0;
Yhat = xgboost_test(Xtest,model,loadmodel);
[XX,YY,~,AUC] = perfcurve(ytest,Yhat,1);
figure;
plot(XX,YY,'LineWidth',2); xlabel('False positive rate'); ylabel('True positive rate'); title('ROC for Classification by Logistic Regression'); grid on
figure;
scatter(Yhat,ytest + 0.1*rand(length(ytest),1)); grid on
unloadlibrary('xgboost')