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

相关推荐
2401_87169652几秒前
如何防止SQL注入利用存储过程_确保存储过程不拼字符串
jvm·数据库·python
2301_796588501 分钟前
如何在 macOS 中使用 launchd 每分钟执行一次 PHP 脚本
jvm·数据库·python
m0_748920361 分钟前
HTML函数在笔记本上卡顿怎么办_笔记本运行HTML函数优化操作【操作】
jvm·数据库·python
耿雨飞6 分钟前
Python 后端开发技术博客专栏 | 第 03 篇 面向对象编程进阶 -- 从 SOLID 原则到 Python 特色 OOP
开发语言·python·面向对象·oop
m0_678485458 分钟前
c++如何提取系统环境变量并直接保存到txt日志中_getenv与ofstream【实战】
jvm·数据库·python
源码站~9 分钟前
基于python的校园代跑(跑腿)系统
开发语言·python
BugShare10 分钟前
一个用 Rust 编写的、速度极快的 Python 包和项目管理器
开发语言·python·rust
qq_3422958212 分钟前
Go语言怎么嵌入静态文件_Go语言embed嵌入文件教程【秒懂】
jvm·数据库·python
耿雨飞15 分钟前
Python 后端开发技术博客专栏 | 第 04 篇 Python 内存管理与垃圾回收 -- 从引用计数到分代回收
开发语言·python·垃圾回收
qq_2069013918 分钟前
如何在Linux上源码编译安装MySQL_CMake配置与依赖包安装
jvm·数据库·python