CuML + Cudf (RAPIDS) 加速python数据分析脚本

如果有人在用Nvidia RAPIDS加速pandas和sklearn等库,请看我这个小示例,可以节省你大量时间。

1. 创建环境

请使用uv,而非conda/mamba。

shell 复制代码
# install uv if not yet

curl -LsSf https://astral.sh/uv/install.sh | sh

uv init data_gpu

cd data_gpu

uv venv --python 3.12

source .venv/bin/activate

# 大的要来了

# 使用阿里云开源镜像

uv pip install \

  -i http://mirrors.aliyun.com/pypi/simple/ \

  --extra-index-url=https://pypi.nvidia.com \

  "cudf-cu12==25.4.*" "cuml-cu12==25.4.*" \

  "polars[pandas,numpy,pyarrow,style,plot,excel,gpu]" \

  polars-u64-idx scikit-learn scipy statsmodels tqdm ipykernel jupyter --prerelease=allow --index-strategy unsafe-best-match

2. 在脚本中启用

python 复制代码
import cudf.pandas
cudf.pandas.install()
from cuml.accel.core import install as cuml_install
cuml_install(disable_uvm=False)
import pandas as pd
import polars as pl
import numpy as np
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler

现在,pandas, sklearn, polars都有GPU加持。但是并非所有函数都受支持。具体情况自己去看官方文档。

另外,不要使用 python -m cuml.accel my_script.py,这样你就无法向my_script.py传自己的参数。

相关推荐
敏编程8 小时前
一天一个Python库:tomlkit - 轻松解析和操作TOML配置
python
南滑散修8 小时前
机器学习(四):混合高斯模型GMM
人工智能·机器学习
2401_879693878 小时前
使用Python进行图像识别:CNN卷积神经网络实战
jvm·数据库·python
yunyun321238 小时前
机器学习模型部署:将模型转化为Web API
jvm·数据库·python
FluxMelodySun8 小时前
机器学习(二十五) 降维:主成分分析(PCA)及特征值分解
人工智能·算法·机器学习
团子和二花9 小时前
openclaw平替之nanobot源码解析(七):Gateway与多渠道集成
python·gateway·agent·智能体·openclaw·nanobot
未知鱼9 小时前
Python安全开发之简易目录扫描器(含详细注释)
开发语言·python·安全
Be1k09 小时前
推荐一款语雀知识库批量导出工具
python·gui·工具·语雀·批量导出·原创
2301_780669869 小时前
一篇文章入门机器学习与PyTorch张量
机器学习
Sunshine for you10 小时前
如何用FastAPI构建高性能的现代API
jvm·数据库·python