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

相关推荐
葫三生2 分钟前
三生原理与《涌现:从简单规则到复杂世界》在“简单规则生成复杂系统”核心思路上存在理论呼应?
人工智能·科技·算法·机器学习·开源
2601_9627806912 分钟前
管理科学本科应届生 经营分析与供应链分析岗位求职
数据分析
杨女士YRJ19 分钟前
python+pytest+01
python·pytest
鸽芷咕26 分钟前
Mu Editor 鸿蒙 PC 适配全记录:用 Qt 与嵌入式 CPython 重建教学型 Python IDE
python·qt·harmonyos
YangYang9YangYan35 分钟前
2026 校招管理会计 JD 拆解,数据分析能力要求与工具清单
java·数据库·数据分析
微软技术分享43 分钟前
基于 HuggingFace Tokenizers 训练自定义分词器
python·ubuntu·大模型·huggingface
gf13211111 小时前
python_调用远程服务器上的openclaw
服务器·python·php
lbb 小魔仙1 小时前
Jupyter Notebook / Lab 深度配置指南:插件 + 内核 + 远程访问 + 容器化部署
ide·python·jupyter
2601_962300471 小时前
python是跨平台的吗
python·开源·跨平台·面向对象·
2401_844582951 小时前
软件架构设计与持续重构:模块化开发实战建
python