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传自己的参数。

相关推荐
老歌老听老掉牙22 分钟前
斜抛运动问题分析:给定最大高度与墙面位置的轨迹与时间求解
python·斜抛运动
言乐629 分钟前
Python自动去除水印
开发语言·python·django·virtualenv·pygame
czq_268671948733 分钟前
Python打卡第31天
开发语言·python
invicinble33 分钟前
python 编程语言 认识维度
开发语言·数据库·python
AC赳赳老秦35 分钟前
数据采集全链路审计留痕:用 OpenClaw 实现合规审计与追溯
开发语言·汇编·python·php·swift·deepseek·openclaw
张铁霖1 小时前
深度解析:AI三次浪潮与机器学习三种范式,
python
会议咨询1 小时前
2026年计算机技术、信息工程与机器学习国际会议(CIML 2026)
机器学习·计算机技术·信息工程
明月_清风1 小时前
DuckDB:一个正在改变数据分析方式的数据库
数据库·数据分析·ai编程
学也学不废1 小时前
论文阅读:Advancing Semantic Textual Similarity Modeling
python
风早爽太1 小时前
Python 开发笔记:配置生产环境中 Celery Worker 的独立进程启动方式
python·fastapi