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

相关推荐
小趴蔡ha1 天前
02 Anaconda、Python 与机器学习开发环境入门
python·机器学习·anaconda
2401_868534781 天前
RTOS之RT-Thread & Linux:线程/进程管理与调度核心差异分析
c++·python
数字化转型分享点滴1 天前
富士康、蓝思科技为何选择四化信息?MES制造执行系统的实践
python·科技
wling03011 天前
vasp虚频计算-python脚本
开发语言·windows·python·vasp计算
魔镜前的帅比1 天前
(开源项目)x-claw(总)
python·ai·rust·开源
xrandzj1 天前
Python面向对象编程入门:类、实例、初始化与封装实践
开发语言·python
matlabgoodboy1 天前
计算机毕设代做|Java Python Matlab APP 全套开发设计
java·python·课程设计
用户8356290780511 天前
Python Word 转 PDF 和 PDF 转 Word 指南
后端·python
用户8356290780511 天前
如何使用 Python 加密和保护 Word 文档
后端·python
Fluxproxy1 天前
AI数据集采集、批量模型推理报错频发?AI项目网络稳定性优化实战
python·ai·ai编程