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

相关推荐
布吉岛的石头28 分钟前
Java 程序员第 22 阶段:Function Call 工具调用实战,Java 封装大模型外部能力
java·人工智能·python
l1t33 分钟前
DeepSeek总结的使用实体-组件-系统和基于存在性处理进行Python编程简介
开发语言·python
曲幽39 分钟前
FastApiAdmin 后端接口开发好了,前端管理界面怎么调用与显示?
python·vue3·api·fastapi·web·ant design·view·menu·frontend
rayyy91 小时前
神经网络模型的外推性验证
pytorch·python·深度学习
长乐呀1 小时前
数据集获取与整理
python
三块可乐两块冰1 小时前
rag笔记3
机器学习
清水白石0081 小时前
从脚本到系统:设计一个支持插件、限流、重试与监控的 Python 异步爬虫框架
网络·爬虫·python
deepin_sir1 小时前
02 - 第一个 Python 程序
开发语言·python
徐先生 @_@|||1 小时前
pycharm/IDEA + markdown + 图床(PicList)
ide·python·pycharm·intellij-idea
赵钰老师1 小时前
R语言与作物模型(以DSSAT模型为例)融合应用
开发语言·数据分析·r语言