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/', dependency=TRUE)
因此该命令将为 R 编程安装 CatBoost。