- CatBoost 教程
- CatBoost - 首頁
- CatBoost - 概述
- CatBoost - 架構
- CatBoost - 安裝
- CatBoost - 特性
- CatBoost - 決策樹
- CatBoost - 提升過程
- CatBoost - 核心引數
- CatBoost - 資料預處理
- CatBoost - 處理類別特徵
- CatBoost - 處理缺失值
- CatBoost - 分類器
- CatBoost - 迴歸器
- CatBoost - 排序器
- CatBoost - 模型訓練
- CatBoost - 模型評估指標
- CatBoost - 分類指標
- CatBoost - 過擬合檢測
- CatBoost 與其他提升演算法的比較
- CatBoost 有用資源
- CatBoost - 有用資源
- CatBoost - 討論
CatBoost - 安裝
CatBoost 是一個非常快速、可擴充套件的開源梯度提升決策樹庫,來自 Yandex。CatBoost 的安裝方式取決於您的作業系統和開發環境。本章將介紹在您的系統中安裝 CatBoost 的不同方法。以下是一些常見的方法:
使用 pip (適用於 Python)
這是在您的系統中安裝 CatBoost 最常見和最簡單的方法。您可以在終端上執行以下命令,它將下載庫並將其與依賴項一起安裝到系統中。
開啟您的命令列或終端並執行以下命令:
pip install catboost
在終端或命令提示符中執行上述命令後的過程:
Collecting catboost
Downloading catboost-1.2.7-cp312-cp312-macosx_11_0_universal2.whl.metadata (1.2 kB)
Requirement already satisfied: graphviz in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from catboost) (0.20.3)
Requirement already satisfied: matplotlib in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from catboost) (3.9.2)
Collecting numpy<2.0,>=1.16.0 (from catboost)
Downloading numpy-1.26.4-cp312-cp312-macosx_11_0_arm64.whl.metadata (61 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.1/61.1 kB 1.9 MB/s eta 0:00:00
Requirement already satisfied: pandas>=0.24 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from catboost) (2.2.2)
Requirement already satisfied: scipy in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from catboost) (1.14.1)
Collecting plotly (from catboost)
Downloading plotly-5.24.1-py3-none-any.whl.metadata (7.3 kB)
Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from catboost) (1.16.0)
Requirement already satisfied: python-dateutil>=2.8.2 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from pandas>=0.24->catboost) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from pandas>=0.24->catboost) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from pandas>=0.24->catboost) (2023.4)
Requirement already satisfied: contourpy>=1.0.1 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from matplotlib->catboost) (1.3.0)
Requirement already satisfied: cycler>=0.10 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from matplotlib->catboost) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from matplotlib->catboost) (4.53.1)
Requirement already satisfied: kiwisolver>=1.3.1 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from matplotlib->catboost) (1.4.7)
Requirement already satisfied: packaging>=20.0 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from matplotlib->catboost) (24.1)
Requirement already satisfied: pillow>=8 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from matplotlib->catboost) (10.3.0)
Requirement already satisfied: pyparsing>=2.3.1 in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (from matplotlib->catboost) (3.1.4)
Collecting tenacity>=6.2.0 (from plotly->catboost)
Downloading tenacity-9.0.0-py3-none-any.whl.metadata (1.2 kB)
Downloading catboost-1.2.7-cp312-cp312-macosx_11_0_universal2.whl (27.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 27.0/27.0 MB 4.7 MB/s eta 0:00:0000:0100:01
Downloading numpy-1.26.4-cp312-cp312-macosx_11_0_arm64.whl (13.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.7/13.7 MB 3.6 MB/s eta 0:00:0000:0100:01
Downloading plotly-5.24.1-py3-none-any.whl (19.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 19.1/19.1 MB 4.7 MB/s eta 0:00:0000:0100:01
Downloading tenacity-9.0.0-py3-none-any.whl (28 kB)
Installing collected packages: tenacity, numpy, plotly, catboost
Attempting uninstall: numpy
Found existing installation: numpy 2.1.1
Uninstalling numpy-2.1.1:
Successfully uninstalled numpy-2.1.1
Successfully installed catboost-1.2.7 numpy-1.26.4 plotly-5.24.1 tenacity-9.0.0
[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: pip install --upgrade pip
Note: you may need to restart the kernel to use updated packages.
使用 Conda (適用於 Anaconda 使用者)
如果您使用的是 Anaconda 或 Miniconda,則可以使用 Conda 安裝 CatBoost。執行以下命令時,它將下載必要的包和依賴項,並將其安裝到您的系統中。
conda install -c conda-forge catboost
終端輸出通常如下所示:
(base) $ conda install -c conda-forge catboost
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /path/to/conda/environment
added / updated specs:
- catboost
The following packages will be downloaded:
package | build
------------------------------|-----------------
catboost-1.1 | py38h9b699db_0 16.0 MB
libcxx-11.1.0 | habf9029_0 1.3 MB
libgfortran-5.4.0 | h6c81a4c_10 2.2 MB
openmp-4.5 | h44a4d74_1 3.1 MB
------------------------------------------------------------
Total: 22.6 MB
The following NEW packages will be INSTALLED:
catboost conda-forge/osx-64::catboost-1.1-py38h9b699db_0
libcxx conda-forge/osx-64::libcxx-11.1.0-habf9029_0
libgfortran conda-forge/osx-64::libgfortran-5.4.0-h6c81a4c_10
openmp conda-forge/osx-64::openmp-4.5-h44a4d74_1
Proceed ([y]/n)? y
Downloading and Extracting Packages
catboost-1.1 | 16.0 MB | ########## | 100%
libcxx-11.1.0 | 1.3 MB | ########## | 100%
libgfortran-5.4.0 | 2.2 MB | ########## | 100%
openmp-4.5 | 3.1 MB | ########## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
從原始碼構建
如果您是高階使用者,並且想要最新版本,則可以從原始碼構建 CatBoost。因此,請安裝 CMake、Git、Python 和系統所需的其它構建工具。首先,您需要克隆 CatBoost 倉庫:
git clone https://github.com/catboost/catboost.git
終端輸出如下:
$ git clone https://github.com/catboost/catboost.git Cloning into 'catboost'... remote: Enumerating objects: 345600, done. remote: Counting objects: 100% (2147/2147), done. remote: Compressing objects: 100% (1098/1098), done. remote: Total 345600 (delta 1345), reused 1623 (delta 1019), pack-reused 343453 Receiving objects: 100% (345600/345600), 297.60 MiB | 5.50 MiB/s, done. Resolving deltas: 100% (266248/266248), done.
執行上述命令後,您需要導航到克隆的目錄:
cd catboost
然後像下面這樣構建專案:
./ya make -r -DUSE_SYSTEM_PYTHON=1 catboost/python-package
終端輸出如下:
$ ./ya make -r -DUSE_SYSTEM_PYTHON=1 catboost/python-package Configuring the build... [INFO] [18:34:56] Project configuration complete [INFO] [18:34:57] Building CatBoost package... [INFO] [18:34:58] Running CMake... [INFO] [18:35:02] Generating build system... [INFO] [18:35:03] Build started... [ 10%] Building CXX object contrib/libs/oblivious_tree/CMakeFiles/oblivious_tree.dir/tree.cpp.o [ 20%] Building CXX object contrib/libs/model/CMakeFiles/model.dir/model.cpp.o [ 30%] Linking CXX static library libcatboostmodel.a [ 40%] Building wheel for Python package [ 60%] Linking CXX shared library libcatboost.so [ 80%] Generating Python bindings... [100%] Completed successfully
最後安裝包:
cd catboost/python-package pip install .
安裝包後,上述命令的輸出如下:
$ pip install . Processing /path/to/catboost/python-package Preparing metadata (setup.py) ... done Requirement already satisfied: numpy in /path/to/conda/env/lib/python3.8/site-packages (from catboost==1.1) (1.20.0) Requirement already satisfied: six in /path/to/conda/env/lib/python3.8/site-packages (from catboost==1.1) (1.15.0) Building wheels for collected packages: catboost Building wheel for catboost (setup.py) ... done Created wheel for catboost: filename=catboost-1.1-cp38-cp38-linux_x86_64.whl size=1234567 Stored in directory: /tmp/pip-ephem-wheel-cache-abcd1234 Successfully built catboost Installing collected packages: catboost Successfully installed catboost-1.1
安裝 R 版本
如果您想使用 R 程式語言,則可以使用以下命令安裝 R 版本的 CatBoost。要執行該命令,您只需開啟 R 控制檯或 RStudio,然後執行該命令:
install.packages('catboost', repos = 'https://cloud.r-project.org/', dependencies=TRUE)
此命令將安裝 R 程式語言的 CatBoost。
廣告