Ubuntu16.04環境下Python下Lightgbm機器學習庫的配置
一、Lightgbm簡介
xgboost的出現,讓調參俠們告別了傳統的機器學習演算法們:RF、GBM、SVM、LASSO等等,而微軟推出了一個新的boosting框架Lightgbm更是向前進一步,漸漸有取代的xgboost這一開源框架地位的趨勢。
相比於xgboost,Lightgbm速度大幅度提升,精度與xgboost不相上下。但是易用性和特性相比xgboost還有待提高,cv,early stopping這些非常重要的特性並沒有找到。同時,支援一些語言的介面還有待完善(目前2018.05.12在官方wiki裡面只看到了支援Python的API介面)
二、Lightgbm安裝
參見官方wiki:https://lightgbm.readthedocs.io/en/latest/Installation-Guide.html#
先檢查系統中是否安裝了cmake:
[email protected]:~$ sudo apt-get install cmake [sudo] password for yuhuiliu: Reading package lists... Done Building dependency tree Reading state information... Done cmake is already the newest version (3.5.1-1ubuntu3). The following packages were automatically installed and are no longer required: bbswitch-dkms dkms lib32gcc1 libc6-i386 libjansson4 libvdpau1 libxnvctrl0 mesa-vdpau-drivers screen-resolution-extra vdpau-driver-all xserver-xorg-legacy Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
顯示cmake已經成功安裝,執行以下命令:
git clone --recursive https://github.com/Microsoft/LightGBM ; cd LightGBM
mkdir build ; cd build
cmake ..
make -j4
編譯好了LightGBM之後,參照之前瀏覽的https://stackoverflow.com/questions/44212706/why-importerror-no-module-named-lightgbm進入LightGBM/Python-package 中執行setup.py檔案[email protected]:~/LightGBM/python-package$ sudo python3 setup.py install running install creating compile/include creating compile/include/LightGBM copying ../include/LightGBM/tree_learner.h -> ./compile/include/LightGBM copying ../include/LightGBM/application.h -> ./compile/include/LightGBM copying ../include/LightGBM/metric.h -> ./compile/include/LightGBM copying ../include/LightGBM/export.h -> ./compile/include/LightGBM copying ../include/LightGBM/feature_group.h -> ./compile/include/LightGBM creating compile/include/LightGBM/utils copying ../include/LightGBM/utils/random.h -> ./compile/include/LightGBM/utils copying ../include/LightGBM/utils/threading.h -> ./compile/include/LightGBM/utils copying ../include/LightGBM/utils/file_io.h -> ./compile/include/LightGBM/utils copying ../include/LightGBM/utils/openmp_wrapper.h -> ./compile/include/LightGBM/utils copying ../include/LightGBM/utils/log.h -> ./compile/include/LightGBM/utils copying ../include/LightGBM/utils/array_args.h -> ./compile/include/LightGBM/utils copying ../include/LightGBM/utils/common.h -> ./compile/include/LightGBM/utils copying ../include/LightGBM/utils/text_reader.h -> ./compile/include/LightGBM/utils copying ../include/LightGBM/utils/pipeline_reader.h -> ./compile/include/LightGBM/utils copying ../include/LightGBM/prediction_early_stop.h -> ./compile/include/LightGBM copying ../include/LightGBM/tree.h -> ./compile/include/LightGBM copying ../include/LightGBM/objective_function.h -> ./compile/include/LightGBM copying ../include/LightGBM/c_api.h -> ./compile/include/LightGBM copying ../include/LightGBM/network.h -> ./compile/include/LightGBM copying ../include/LightGBM/lightgbm_R.h -> ./compile/include/LightGBM copying ../include/LightGBM/R_object_helper.h -> ./compile/include/LightGBM copying ../include/LightGBM/config.h -> ./compile/include/LightGBM copying ../include/LightGBM/json11.hpp -> ./compile/include/LightGBM copying ../include/LightGBM/dataset.h -> ./compile/include/LightGBM copying ../include/LightGBM/meta.h -> ./compile/include/LightGBM copying ../include/LightGBM/bin.h -> ./compile/include/LightGBM copying ../include/LightGBM/boosting.h -> ./compile/include/LightGBM copying ../include/LightGBM/dataset_loader.h -> ./compile/include/LightGBM creating compile/src creating compile/src/metric copying ../src/metric/map_metric.hpp -> ./compile/src/metric copying ../src/metric/binary_metric.hpp -> ./compile/src/metric copying ../src/metric/metric.cpp -> ./compile/src/metric copying ../src/metric/regression_metric.hpp -> ./compile/src/metric copying ../src/metric/xentropy_metric.hpp -> ./compile/src/metric copying ../src/metric/multiclass_metric.hpp -> ./compile/src/metric copying ../src/metric/dcg_calculator.cpp -> ./compile/src/metric copying ../src/metric/rank_metric.hpp -> ./compile/src/metric copying ../src/c_api.cpp -> ./compile/src creating compile/src/treelearner copying ../src/treelearner/gpu_tree_learner.h -> ./compile/src/treelearner copying ../src/treelearner/split_info.hpp -> ./compile/src/treelearner copying ../src/treelearner/leaf_splits.hpp -> ./compile/src/treelearner copying ../src/treelearner/feature_parallel_tree_learner.cpp -> ./compile/src/treelearner copying ../src/treelearner/data_partition.hpp -> ./compile/src/treelearner copying ../src/treelearner/serial_tree_learner.cpp -> ./compile/src/treelearner copying ../src/treelearner/voting_parallel_tree_learner.cpp -> ./compile/src/treelearner copying ../src/treelearner/feature_histogram.hpp -> ./compile/src/treelearner copying ../src/treelearner/gpu_tree_learner.cpp -> ./compile/src/treelearner copying ../src/treelearner/serial_tree_learner.h -> ./compile/src/treelearner creating compile/src/treelearner/ocl copying ../src/treelearner/ocl/histogram64.cl -> ./compile/src/treelearner/ocl copying ../src/treelearner/ocl/histogram16.cl -> ./compile/src/treelearner/ocl copying ../src/treelearner/ocl/histogram256.cl -> ./compile/src/treelearner/ocl copying ../src/treelearner/parallel_tree_learner.h -> ./compile/src/treelearner copying ../src/treelearner/data_parallel_tree_learner.cpp -> ./compile/src/treelearner copying ../src/treelearner/tree_learner.cpp -> ./compile/src/treelearner creating compile/src/network copying ../src/network/linker_topo.cpp -> ./compile/src/network copying ../src/network/socket_wrapper.hpp -> ./compile/src/network copying ../src/network/linkers_mpi.cpp -> ./compile/src/network copying ../src/network/linkers_socket.cpp -> ./compile/src/network copying ../src/network/linkers.h -> ./compile/src/network copying ../src/network/network.cpp -> ./compile/src/network copying ../src/main.cpp -> ./compile/src creating compile/src/boosting copying ../src/boosting/score_updater.hpp -> ./compile/src/boosting copying ../src/boosting/goss.hpp -> ./compile/src/boosting copying ../src/boosting/dart.hpp -> ./compile/src/boosting copying ../src/boosting/gbdt_model_text.cpp -> ./compile/src/boosting copying ../src/boosting/boosting.cpp -> ./compile/src/boosting copying ../src/boosting/rf.hpp -> ./compile/src/boosting copying ../src/boosting/prediction_early_stop.cpp -> ./compile/src/boosting copying ../src/boosting/gbdt_prediction.cpp -> ./compile/src/boosting copying ../src/boosting/gbdt.h -> ./compile/src/boosting copying ../src/boosting/gbdt.cpp -> ./compile/src/boosting creating compile/src/application copying ../src/application/predictor.hpp -> ./compile/src/application copying ../src/application/application.cpp -> ./compile/src/application copying ../src/lightgbm_R.cpp -> ./compile/src creating compile/src/objective copying ../src/objective/xentropy_objective.hpp -> ./compile/src/objective copying ../src/objective/regression_objective.hpp -> ./compile/src/objective copying ../src/objective/objective_function.cpp -> ./compile/src/objective copying ../src/objective/binary_objective.hpp -> ./compile/src/objective copying ../src/objective/rank_objective.hpp -> ./compile/src/objective copying ../src/objective/multiclass_objective.hpp -> ./compile/src/objective creating compile/src/io copying ../src/io/parser.hpp -> ./compile/src/io copying ../src/io/parser.cpp -> ./compile/src/io copying ../src/io/dense_nbits_bin.hpp -> ./compile/src/io copying ../src/io/dense_bin.hpp -> ./compile/src/io copying ../src/io/ordered_sparse_bin.hpp -> ./compile/src/io copying ../src/io/tree.cpp -> ./compile/src/io copying ../src/io/sparse_bin.hpp -> ./compile/src/io copying ../src/io/file_io.cpp -> ./compile/src/io copying ../src/io/metadata.cpp -> ./compile/src/io copying ../src/io/dataset.cpp -> ./compile/src/io copying ../src/io/config.cpp -> ./compile/src/io copying ../src/io/json11.cpp -> ./compile/src/io copying ../src/io/bin.cpp -> ./compile/src/io copying ../src/io/dataset_loader.cpp -> ./compile/src/io copying ../windows/LightGBM.sln -> ./compile/windows copying ../windows/LightGBM.vcxproj -> ./compile/windows copying ../CMakeLists.txt -> ./compile/ copying ../LICENSE -> ./ INFO:LightGBM:Starting to compile the library. INFO:LightGBM:Starting to compile with CMake. running build running build_py INFO:root:Generating grammar tables from /usr/lib/python3.5/lib2to3/Grammar.txt INFO:root:Generating grammar tables from /usr/lib/python3.5/lib2to3/PatternGrammar.txt running egg_info writing dependency_links to lightgbm.egg-info/dependency_links.txt writing top-level names to lightgbm.egg-info/top_level.txt writing lightgbm.egg-info/PKG-INFO writing requirements to lightgbm.egg-info/requires.txt reading manifest file 'lightgbm.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' no previously-included directories found matching 'build' warning: no files found matching '*.txt' warning: no files found matching '*.so' under directory 'lightgbm' warning: no files found matching '*.dll' under directory 'compile/Release' warning: no files found matching '*' under directory 'compile/compute' warning: no files found matching 'LightGBM.vcxproj.filters' under directory 'compile/windows' warning: no files found matching '*.dll' under directory 'compile/windows/x64/DLL' warning: no previously-included files matching '*.py[co]' found anywhere in distribution writing manifest file 'lightgbm.egg-info/SOURCES.txt' running install_lib creating /usr/local/lib/python3.5/dist-packages/lightgbm copying build/lib/lightgbm/VERSION.txt -> /usr/local/lib/python3.5/dist-packages/lightgbm copying build/lib/lightgbm/__init__.py -> /usr/local/lib/python3.5/dist-packages/lightgbm copying build/lib/lightgbm/plotting.py -> /usr/local/lib/python3.5/dist-packages/lightgbm copying build/lib/lightgbm/engine.py -> /usr/local/lib/python3.5/dist-packages/lightgbm copying build/lib/lightgbm/compat.py -> /usr/local/lib/python3.5/dist-packages/lightgbm copying build/lib/lightgbm/callback.py -> /usr/local/lib/python3.5/dist-packages/lightgbm copying build/lib/lightgbm/libpath.py -> /usr/local/lib/python3.5/dist-packages/lightgbm copying build/lib/lightgbm/basic.py -> /usr/local/lib/python3.5/dist-packages/lightgbm copying build/lib/lightgbm/sklearn.py -> /usr/local/lib/python3.5/dist-packages/lightgbm INFO:root:Installing lib_lightgbm from: ['../lib_lightgbm.so', 'compile/lib_lightgbm.so'] copying ../lib_lightgbm.so -> /usr/local/lib/python3.5/dist-packages/lightgbm byte-compiling /usr/local/lib/python3.5/dist-packages/lightgbm/__init__.py to __init__.cpython-35.pyc byte-compiling /usr/local/lib/python3.5/dist-packages/lightgbm/plotting.py to plotting.cpython-35.pyc byte-compiling /usr/local/lib/python3.5/dist-packages/lightgbm/engine.py to engine.cpython-35.pyc byte-compiling /usr/local/lib/python3.5/dist-packages/lightgbm/compat.py to compat.cpython-35.pyc byte-compiling /usr/local/lib/python3.5/dist-packages/lightgbm/callback.py to callback.cpython-35.pyc byte-compiling /usr/local/lib/python3.5/dist-packages/lightgbm/libpath.py to libpath.cpython-35.pyc byte-compiling /usr/local/lib/python3.5/dist-packages/lightgbm/basic.py to basic.cpython-35.pyc byte-compiling /usr/local/lib/python3.5/dist-packages/lightgbm/sklearn.py to sklearn.cpython-35.pyc running install_egg_info Copying lightgbm.egg-info to /usr/local/lib/python3.5/dist-packages/lightgbm-2.1.1.egg-info running install_scripts
按照之前在wiki上面的guide學到的套路應該配置到這裡,lightgbm庫就能夠直接用了,
然而使用conda list | grep lig命令悲傷的並沒有發現lightgbm這個包:
[email protected]:~$ conda list |grep lig
[email protected]:~$
再在python環境中import試一下:[email protected]:~$ python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lightgbm as lgb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lightgbm'
果然沒有lightgbm這個module。
鬱悶,刪了build/檔案重新配置好幾次都顯示沒有‘lightgbm’這個包,也檢查了cmake的版本,最下面這臺sinc-server工作站是配置成功的,作為參照:
[email protected]:~$ sudo apt-get install cmake
[sudo] password for yuhuiliu:
Reading package lists... Done
Building dependency tree
Reading state information... Done
cmake is already the newest version (3.5.1-1ubuntu3).
[email protected]:~$ dpkg -l |grep cmak
ii cmake 3.5.1-1ubuntu1 amd64 cross-platform, open-source make system
ii cmake-data 3.5.1-1ubuntu1 all CMake data files (modules, templates and documentation)
這時不妨換個思路 ,參照http://lightgbm.apachecn.org/zh/2.0.11/Python-Intro.html#id1,檢視wiki的Python Package Introduction,發現pip的源已經加進來這個source,這樣我們就利用pip命令進行安裝:
[email protected]:~$ pip install lightgbm
The directory '/home/yuhuiliu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/yuhuiliu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting lightgbm
Downloading https://files.pythonhosted.org/packages/bf/01/45e209af10fd16537df0c5d8a5474c286554c3eaf9ddb0ce04113f1e8506/lightgbm-2.1.1-py2.py3-none-manylinux1_x86_64.whl (711kB)
100% |████████████████████████████████| 716kB 709kB/s
Requirement already satisfied: numpy in ./anaconda3/lib/python3.6/site-packages (from lightgbm)
Requirement already satisfied: scikit-learn in ./anaconda3/lib/python3.6/site-packages (from lightgbm)
Requirement already satisfied: scipy in ./anaconda3/lib/python3.6/site-packages (from lightgbm)
Installing collected packages: lightgbm
Successfully installed lightgbm-2.1.1
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
再來檢查一下:
[email protected]:~$ conda list |grep lig
lightgbm 2.1.1 <pip>
已經成功安裝了lightgbm:
[email protected]:~$ python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lightgbm as lgb
>>>
相關推薦
Ubuntu16.04環境下Python下Lightgbm機器學習庫的配置
一、Lightgbm簡介 xgboost的出現,讓調參俠們告別了傳統的機器學習演算法們:RF、GBM、SVM、LASSO等等,而微軟推出了一個新的boosting框架Lightgbm更是向前進一步,漸漸有取代的xgboost這一開源框架地位的趨勢。相比於xgboost,L
分類解讀Spark下的39個機器學習庫
轉自小象學院的文章(http://xxwenda.com/article/584),後續準備逐個試驗一下。當然有不少已經測試過的。 Apache Spark 本身 1.MLlibAMPLabSpark最初誕生於伯克利 AMPLab實驗室,如今依然還是AMPLab所致力的專
Python/scikit-learn機器學習庫(特徵選取)
去除方差小的特徵 設定一個方差閾值,沒有達到這個方差閾值的特徵都會被丟棄。 VarianceThreshold,演算法輸入只要求特徵(X),不需要輸入結果(Y)。 from sklearn.feature_selection import Varia
Python/scikit-learn機器學習庫(SVM支援向量機)
SVM SVM用於分類、迴歸、異常檢測。 優點: 高維空間有效。 維度小於樣本數時依然有效。 樣本少時表現不好。 分類 多分類: SVC、NuSVC、LinearSVC。SVMs決策函式依賴於訓練資料中一部分,這些向量稱為支援向量。 NuSVC
Ubuntu16.04環境下Python下xlearn機器學習庫的配置
一、xlearn的簡介參見:https://www.zhihu.com/question/37256015/answer/268151326,http://www.sohu.com/a/206728248_206784 在機器學習裡,除了深度學習和樹模型 (GB
1.VMware Workstation 12.5下Ubuntu16.04環境搭建
鏡像文件 超級 http -1 用戶權限 文件 tps ubuntu 創建 一、需要下載的資源: 1. 下載VMware Workstation 鏈接: https://pan.baidu.com/s/1nuDEc3n 密碼: 89xc 2. 下載Ubunt
Ubuntu16.04環境下通過Cmake管理Opencv專案
Ubuntu16.04環境下通過Cmake管理Opencv專案 1、新建qt cmake工程 New Project -> Non-Qt Project -> Plain C++ Application 2、CMakeLists.txt檔案內
Ubuntu16.04環境下搭建Hadoop3.0.3偽分散式叢集
最近剛好趕上雙11騰訊促銷,於是搶購了一個8核16G記憶體的雲伺服器,加上業務上需要用到hadoop,hive,於是想搭建搭建一個hadoop分散式叢集,但是限於自己手頭上伺服器數量不多,因此打算先搭建一個hadoop偽分散式叢集。 首先介紹一下我的安裝
[joysticke]使用Ubuntu16.04環境下讀取USB手柄/方向盤資訊
1.獲取裝置的埠 在插入裝置時,在/dev/input目錄下 ,作業系統會為每一個裝置分配event號,先插上的為event0,後插上的為event1。 查詢裝置的裝置號用如下指令: cat /proc/bus/input/devices 獲得如下輸出 1 I: Bus=0
Ubuntu16.04環境下命令列安裝驅動
去官網查適合自己的GPU驅動: 依次執行如下語句安裝: sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt-get up
ubuntu16.04環境下, Ctrl+Alt+F1 進入終端字元介面 登入出現login incorrect解決辦法
在安裝nvidia驅動的時候,需要ubuntu Ctrl+Alt+F1 進入終端字元介面 登入出現login incorrect解決辦法: 如圖 出現這種情況的原因有兩個: 輸入密碼的時候,不可以用小鍵盤。 在tty介面應先登陸自己的賬號和密碼,如下圖:
faster-rcnn在ubuntu16.04環境下的超級詳細的配置
$ sudo cp Makefile.config.example Makefile.config # 備份配置檔案 $ sudo gedit Makefile.config # 修改編譯檔案 `````````````````````````````````````````````````````
Ubuntu16.04環境下安裝CUDA、cudnn、Caffe、Tensorflow、pytorch
【主題】Ubuntu16.04環境下安裝CUDA、cudnn、Caffe、Tensorflow、pytorch 【環境】 筆記本: 筆記本:惠普 Pavilion NoteBook 系統環境:Ubuntu16.04+Win10 64位雙系統 顯示卡:NVIDIA GT
Ubuntu16.04環境下PyTorch簡易安裝教程
安裝NVIDIA GPU顯示卡驅動 如果需要安裝cuda版本的PyTorch,電腦也有獨立顯示卡的時候,一般需要更新一下Ubuntu獨立顯示卡驅動。否則即使安裝了cuda版本的PyTorch也沒辦法使用GPU。 因為我的膝上型電腦顯示卡是NVIDIA的,所以
Caffe學習1——在ubuntu16.04環境下安裝Caffe(CPU)
目前在網上,已經存在很多的Caffe安裝教程。本文主要介紹筆者在安裝Caffe——CPU版本所遇到的問題(主要參考了網上的 部落格) ,以及相關解決方法。以下給出基於ubuntu 16.04系統的Caffe的CPU安裝步驟:1. 安裝gitsudo apt-get inst
Ubuntu16.04環境下git安裝與使用
一、git的安裝 參見廖雪峰的git教程,在Linux使用sudo apt-get install git即可。二、建立本地版本庫 在需要建立版本庫進行管理的根資料夾下,輸入git init命令,通過git init命令將這個資料夾變成git可以管理的倉庫:H:\
Ubuntu16.04環境下MySQL5.7安裝&配置以及遠端訪問
mysql> set character_set_client=utf8; mysql> set character_set_connection=utf8; mysql> set character_set_database=utf8; mysql> set charact
ubuntu16.04環境下重裝windows10
list err label 選擇 sea 操作 引導 arc 格式 本文針對MBR引導啟動,在ubuntu16.04和windows原來的雙系統環境下重裝windows10,重裝之前請務必備份好原有系統中的所有數據!!! 1,從微軟官網下載win10鏡像文件。 2,安裝u
Ubuntu16.04環境下Vim 配置 for HTML,CSS,JAVASCRIPT(1)
vimr vimrc ref res runt sta all mpat () 參考了三篇文章: VIM配置---面向前端 使用Vundle管理配置Vim基本插件 CSS 語法高亮 1、安裝Vundle git clone https://github.com/Vund
ubuntu16.04在英文狀態下安裝中文語言包的過程(法一:圖形界面的方式) 以及 安裝中文語言包後無法選擇漢語問題的解決 以及 安裝搜狗中文輸入法的方法
完成 pan 設置 狀態 重啟 round font back 問題 1、筆記本安裝的ubuntu是桌面的,安裝語言包非常方便,桌面版本選擇 齒輪 --> System --> System Settings... --> Language Suppor