【AutoML】一个用于图像、文本、时间序列和表格数据的AutoML

news2025/4/17 0:17:15

一个用于图像、文本、时间序列和表格数据的AutoML

  • AutoGluon介绍
    • 安装AutoGluon
    • 快速上手
  • 参考资料

AutoGluon自动化机器学习任务,使您能够在应用程序中轻松实现强大的预测性能。只需几行代码就可以训练和部署有关图像,文本,时间序列和表格数据的高准确机器学习以及深度学习模型。

项目地址:https://github.com/autogluon/autogluon
AutoGluon
本文中的代码使用Google colab实现。

AutoGluon介绍

AutoGluon
AutoGluon: AutoML for Image, Text, Time Series, and Tabular Data
主要特点:

  • 快速原型制作:用几行代码在原始数据上构建机器学习解决方案。
  • 最先进的技术:无需专业知识即可自动利用SOTA模型。
  • 易于部署:从实验到生产云预测因子和预建装容器。
  • 可自定义:可扩展使用自定义功能处理,模型和指标。

快速上手:

pip install autogluon

安装AutoGluon

对于Linux操作环境,如果有GPU,则执行如下:

pip install -U pip
pip install -U setuptools wheel

# Install the proper version of PyTorch following https://pytorch.org/get-started/locally/
pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --index-url https://download.pytorch.org/whl/cu118

pip install autogluon

快速上手

在本教程中将看到如何使用AutoGluon的TabularPredictor来预测基于表格数据集中其他列的目标列的值。

首先确保已安装AutoGluon,然后导入Autogluon的TabulardataTasetTabular Pressixor。我们将使用前者加载数据和后者来训练模型并做出预测。

!python -m pip install --upgrade pip
!python -m pip install autogluon

加载TabulardataTasetTabular Pressixor

from autogluon.tabular import TabularDataset, TabularPredictor

(1)示例数据
在本教程中将使用《自然》杂志第7887期封面故事中的数据集:人工智能引导的数学定理直觉。我们的目标是根据knot(绳结)的特性来预测它的特征。我们从原始数据中抽取了10K 训练和5K 测试的样本。采样的数据集使本教程快速运行,但是如果需要,AutoGluon 可以处理完整的数据集。

直接从URL加载此数据集。Autogluon的Tabulardataset是Pandas DataFrame的一个子类,因此也可以在TabulardatAset上使用任何Dataframe方法。

data_url = 'https://raw.githubusercontent.com/mli/ag-docs/main/knot_theory/'
train_data = TabularDataset(f'{data_url}train.csv')
train_data.head()

训练数据
我们的目标存储在“signature”列中,该列有18个独特的整数。即使pandas没有正确地将此数据类型识别为分类,Autogluon也会解决此问题。

label = 'signature'
train_data[label].describe()

count 10000.000000
mean -0.022000
std 3.025166
min -12.000000
25% -2.000000
50% 0.000000
75% 2.000000
max 12.000000
Name: signature, dtype: float64
(2)训练
现在,我们通过指定“signature”列名称,然后在数据集上使用TagularPredictor.fit()在数据集上进行训练。我们不需要指定任何其他参数。Autogluon将认识到这是一项多类分类任务,执行自动功能工程,训练多个模型,然后将模型集成以创建最终预测器

predictor = TabularPredictor(label=label).fit(train_data)

执行过程如下:

No path specified. Models will be saved in: "AutogluonModels/ag-20240326_144222"
No presets specified! To achieve strong results with AutoGluon, it is recommended to use the available presets.
	Recommended Presets (For more details refer to https://auto.gluon.ai/stable/tutorials/tabular/tabular-essentials.html#presets):
	presets='best_quality'   : Maximize accuracy. Default time_limit=3600.
	presets='high_quality'   : Strong accuracy with fast inference speed. Default time_limit=3600.
	presets='good_quality'   : Good accuracy with very fast inference speed. Default time_limit=3600.
	presets='medium_quality' : Fast training time, ideal for initial prototyping.
Beginning AutoGluon training ...
AutoGluon will save models to "AutogluonModels/ag-20240326_144222"
=================== System Info ===================
AutoGluon Version:  1.0.0
Python Version:     3.10.12
Operating System:   Linux
Platform Machine:   x86_64
Platform Version:   #1 SMP PREEMPT_DYNAMIC Sat Nov 18 15:31:17 UTC 2023
CPU Count:          2
Memory Avail:       11.26 GB / 12.67 GB (88.9%)
Disk Space Avail:   41.86 GB / 78.19 GB (53.5%)
===================================================
Train Data Rows:    10000
Train Data Columns: 18
Label Column:       signature
AutoGluon infers your prediction problem is: 'multiclass' (because dtype of label-column == int, but few unique label-values observed).
	First 10 (of 13) unique label values:  [-2, 0, 2, -8, 4, -4, -6, 8, 6, 10]
	If 'multiclass' is not the correct problem_type, please manually specify the problem_type parameter during predictor init (You may specify problem_type as one of: ['binary', 'multiclass', 'regression'])
Problem Type:       multiclass
Preprocessing data ...
Warning: Some classes in the training set have fewer than 10 examples. AutoGluon will only keep 9 out of 13 classes for training and will not try to predict the rare classes. To keep more classes, increase the number of datapoints from these rare classes in the training data or reduce label_count_threshold.
Fraction of data from classes with at least 10 examples that will be kept for training models: 0.9984
Train Data Class Count: 9
Using Feature Generators to preprocess the data ...
Fitting AutoMLPipelineFeatureGenerator...
	Available Memory:                    11534.85 MB
	Train Data (Original)  Memory Usage: 1.37 MB (0.0% of available memory)
	Inferring data type of each feature based on column values. Set feature_metadata_in to manually specify special dtypes of the features.
	Stage 1 Generators:
		Fitting AsTypeFeatureGenerator...
			Note: Converting 5 features to boolean dtype as they only contain 2 unique values.
	Stage 2 Generators:
		Fitting FillNaFeatureGenerator...
	Stage 3 Generators:
		Fitting IdentityFeatureGenerator...
	Stage 4 Generators:
		Fitting DropUniqueFeatureGenerator...
	Stage 5 Generators:
		Fitting DropDuplicatesFeatureGenerator...
	Useless Original Features (Count: 1): ['Symmetry_D8']
		These features carry no predictive signal and should be manually investigated.
		This is typically a feature which has the same value for all rows.
		These features do not need to be present at inference time.
	Types of features in original data (raw dtype, special dtypes):
		('float', []) : 14 | ['chern_simons', 'cusp_volume', 'injectivity_radius', 'longitudinal_translation', 'meridinal_translation_imag', ...]
		('int', [])   :  3 | ['Unnamed: 0', 'hyperbolic_adjoint_torsion_degree', 'hyperbolic_torsion_degree']
	Types of features in processed data (raw dtype, special dtypes):
		('float', [])     : 9 | ['chern_simons', 'cusp_volume', 'injectivity_radius', 'longitudinal_translation', 'meridinal_translation_imag', ...]
		('int', [])       : 3 | ['Unnamed: 0', 'hyperbolic_adjoint_torsion_degree', 'hyperbolic_torsion_degree']
		('int', ['bool']) : 5 | ['Symmetry_0', 'Symmetry_D3', 'Symmetry_D4', 'Symmetry_D6', 'Symmetry_Z/2 + Z/2']
	0.1s = Fit runtime
	17 features in original data used to generate 17 features in processed data.
	Train Data (Processed) Memory Usage: 0.96 MB (0.0% of available memory)
Data preprocessing and feature engineering runtime = 0.2s ...
AutoGluon will gauge predictive performance using evaluation metric: 'accuracy'
	To change this, specify the eval_metric parameter of Predictor()
Automatically generating train/validation split with holdout_frac=0.1, Train Rows: 8985, Val Rows: 999
User-specified model hyperparameters to be fit:
{
	'NN_TORCH': {},
	'GBM': [{'extra_trees': True, 'ag_args': {'name_suffix': 'XT'}}, {}, 'GBMLarge'],
	'CAT': {},
	'XGB': {},
	'FASTAI': {},
	'RF': [{'criterion': 'gini', 'ag_args': {'name_suffix': 'Gini', 'problem_types': ['binary', 'multiclass']}}, {'criterion': 'entropy', 'ag_args': {'name_suffix': 'Entr', 'problem_types': ['binary', 'multiclass']}}, {'criterion': 'squared_error', 'ag_args': {'name_suffix': 'MSE', 'problem_types': ['regression', 'quantile']}}],
	'XT': [{'criterion': 'gini', 'ag_args': {'name_suffix': 'Gini', 'problem_types': ['binary', 'multiclass']}}, {'criterion': 'entropy', 'ag_args': {'name_suffix': 'Entr', 'problem_types': ['binary', 'multiclass']}}, {'criterion': 'squared_error', 'ag_args': {'name_suffix': 'MSE', 'problem_types': ['regression', 'quantile']}}],
	'KNN': [{'weights': 'uniform', 'ag_args': {'name_suffix': 'Unif'}}, {'weights': 'distance', 'ag_args': {'name_suffix': 'Dist'}}],
}
Fitting 13 L1 models ...
Fitting model: KNeighborsUnif ...
	0.2232	 = Validation score   (accuracy)
	0.06s	 = Training   runtime
	0.02s	 = Validation runtime
Fitting model: KNeighborsDist ...
	0.2132	 = Validation score   (accuracy)
	0.04s	 = Training   runtime
	0.02s	 = Validation runtime
Fitting model: NeuralNetFastAI ...
	0.9459	 = Validation score   (accuracy)
	21.81s	 = Training   runtime
	0.02s	 = Validation runtime
Fitting model: LightGBMXT ...
	0.9459	 = Validation score   (accuracy)
	8.91s	 = Training   runtime
	0.21s	 = Validation runtime
Fitting model: LightGBM ...
	0.956	 = Validation score   (accuracy)
	6.37s	 = Training   runtime
	0.12s	 = Validation runtime
Fitting model: RandomForestGini ...
	0.9449	 = Validation score   (accuracy)
	5.6s	 = Training   runtime
	0.09s	 = Validation runtime
Fitting model: RandomForestEntr ...
	0.9499	 = Validation score   (accuracy)
	6.36s	 = Training   runtime
	0.1s	 = Validation runtime
Fitting model: CatBoost ...
	0.956	 = Validation score   (accuracy)
	57.69s	 = Training   runtime
	0.01s	 = Validation runtime
Fitting model: ExtraTreesGini ...
	0.9469	 = Validation score   (accuracy)
	2.16s	 = Training   runtime
	0.11s	 = Validation runtime
Fitting model: ExtraTreesEntr ...
	0.9429	 = Validation score   (accuracy)
	2.06s	 = Training   runtime
	0.16s	 = Validation runtime
Fitting model: XGBoost ...
	0.957	 = Validation score   (accuracy)
	11.36s	 = Training   runtime
	0.36s	 = Validation runtime
Fitting model: NeuralNetTorch ...
	0.9409	 = Validation score   (accuracy)
	41.09s	 = Training   runtime
	0.01s	 = Validation runtime
Fitting model: LightGBMLarge ...
	0.9499	 = Validation score   (accuracy)
	12.24s	 = Training   runtime
	0.33s	 = Validation runtime
Fitting model: WeightedEnsemble_L2 ...
	Ensemble Weights: {'NeuralNetFastAI': 0.22, 'RandomForestEntr': 0.22, 'ExtraTreesGini': 0.171, 'KNeighborsUnif': 0.122, 'RandomForestGini': 0.073, 'XGBoost': 0.073, 'LightGBMXT': 0.049, 'NeuralNetTorch': 0.049, 'LightGBMLarge': 0.024}
	0.966	 = Validation score   (accuracy)
	1.05s	 = Training   runtime
	0.0s	 = Validation runtime
AutoGluon training complete, total runtime = 181.72s ... Best model: "WeightedEnsemble_L2"
TabularPredictor saved. To load, use: predictor = TabularPredictor.load("AutogluonModels/ag-20240326_144222")

根据CPU型号模型拟合应花费几分钟或更短的时间。可以通过指定time_limit参数来更快地进行训练。例如,fit(..., time_limit=60)将在60秒后停止训练。较高的时间限制通常会导致更好的预测性能,并且过度较低的时间限制将阻止AutoGluon训练并结合一组合理的模型。
(3)预测
一旦有一个适合训练数据集的predictor,就可以加载一组数据集以用于预测和评估。

test_data = TabularDataset(f'{data_url}test.csv')

y_pred = predictor.predict(test_data.drop(columns=[label]))
y_pred.head()

执行结果:

Loaded data from: https://raw.githubusercontent.com/mli/ag-docs/main/knot_theory/test.csv | Columns = 19 / 19 | Rows = 5000 -> 5000
0   -4
1    0
2    0
3    4
4    2
Name: signature, dtype: int64

(4)评估
我们可以使用evaluate()函数在测试数据集上评估predictor,该函数测量predictor在未用于拟合模型的数据上的表现。

predictor.evaluate(test_data, silent=True)

执行结果:

{'accuracy': 0.9462,
 'balanced_accuracy': 0.7437099196728706,
 'mcc': 0.9340692878044228}

Autogluon的TabularPredictor还提供了leaderboard()函数,这使我们能够评估每个经过训练的模型在测试数据上的性能。

predictor.leaderboard(test_data)

预测结果
(5)结论
在此教程中,我们看到了Autogluon的基本拟合度,并使用TabularDatasetTabularPredictor预测功能。Autogluon通过不需要特征工程或模型超参数调整来简化模型训练过程。

参考资料

  1. AutoGluon GitHub Repo: https://github.com/autogluon/autogluon
  2. AutoGluon 官方文档:https://auto.gluon.ai/stable/index.html
  3. AutoGluon Quick Start: https://colab.research.google.com/github/autogluon/autogluon/blob/stable/docs/tutorials/tabular/tabular-quick-start.ipynb#scrollTo=EQlCXX50IvBp

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1547149.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

搭建Spark单机版环境

在搭建Spark单机版环境的实战中,首先确保已经安装并配置好了JDK。然后,从群共享下载Spark安装包,并将其上传至目标主机的/opt目录。接着,解压Spark安装包至/usr/local目录,并配置Spark的环境变量,以确保系统…

计算机网络:物理层 - 编码与调制

计算机网络:物理层 - 编码与调制 基本概念编码不归零制编码归零制编码曼彻斯特编码差分曼彻斯特编码 调制调幅调频调相混合调制 基本概念 在计算机网络中,计算机需要处理和传输用户的文字、图片、音频和视频,他们可以统称为消息数据&#xf…

C#学习笔记3:Windows窗口计时器

今日继续我的C#学习之路,今日学习自己制作一个Windows窗口计时器程序: 文章提供源码解释、步骤操作、整体项目工程下载 完成后的效果大致如下:(可选择秒数,有进度条,开始计时按钮等) &#xf…

一周学会Django5 Python Web开发-Django5模型定义

锋哥原创的Python Web开发 Django5视频教程: 2024版 Django5 Python web开发 视频教程(无废话版) 玩命更新中~_哔哩哔哩_bilibili2024版 Django5 Python web开发 视频教程(无废话版) 玩命更新中~共计41条视频,包括:2024版 Django5 Python we…

并发VS并行

参考文章 面试必考的:并发和并行有什么区别? 并发:一个人同时做多件事(射击游戏队友抢装备) 并行:多人同时处理同一件事(射击游戏敌人同时射击对方)

业务服务:xss攻击

文章目录 前言一、使用注解预防1. 添加依赖2. 自定义注解3. 自定义校验逻辑4. 使用 二、使用过滤器1. 添加配置2. 创建配置类3. 创建过滤器4. 创建过滤器类5. 使用 前言 xss攻击时安全领域中非常常见的一种方法,保证我们的系统安全是非常重要的 xss攻击简单来说就…

酷开科技:OTT领域的璀璨明珠

在广袤的科技海洋中,酷开科技犹如一颗璀璨的明珠,以其独特的魅力和卓越的实力,引领着OTT领域的发展。自2014年前后,彩电业遭遇三十年来首次的销量滑坡,整个行业陷入了“寒冬”。在这个艰难的时刻,酷开科技却…

pure-admin

vue-pure-admin: 🔥 全面ESMVue3ViteElement-PlusTypeScript编写的一款后台管理系统(兼容移动端)

GBU3510-ASEMI开关电源整流桥GBU3510

编辑:ll GBU3510-ASEMI开关电源整流桥GBU3510 型号:GBU3510 品牌:ASEMI 封装:GBU-4 平均正向整流电流(Id):35A 最大反向击穿电压(VRM):1000V 产品引线…

【jenkins+cmake+svn管理c++项目】windows修改jenkins的工作目录

jenkins默认的存放源码的workspace是: C:\Users\用户\AppData\Local\Jenkins\.jenkins\workspace。由于jenkins会拉取大量的源代码以及编译生成一些文件,我希望我能自己指定目录作为它的工作空间,放在这里显然不太合适。 那么修改目录的方式有…

windows允许指定IP段访问本地端口

虚拟机内部应用有时候需要访问windows的一些端口,例如数据库或Redis等,默认情况下,需关闭windows上的防火墙才可正常访问。本文通过在防火墙设置允许指定IP段进行访问来处理,不用每次操作都关闭防火墙。 入站规则-》新建规则 完成…

Memcached分布式内存对象数据库

一 Memcached 概念 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态 Web 应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态、数据库驱动网站的速度。 二 在架构中的位置 Memcached 处于前端或中间件后…

(二)Eureka服务搭建,服务注册,服务发现

1.Eureka注册中心 假如我们的服务提供者user-service部署了多个实例,如图: 存在几个问题: order-service在发起远程调用的时候,该如何得知user-service实例的ip地址和端口?有多个user-service实例地址,…

开源博客项目Blog .NET Core源码学习(11:App.Core项目结构分析)

开源博客项目Blog的App.Core项目主要定义数据库表对应的数据类,同时定义配置文件读取、日志记录、辅助缓存等辅助类。App.Core项目安装的Nuget包不多,仅包括SqlSugarCore和Microsoft.Extensions.DependencyInjectio两类。   App.Core项目的顶层文件夹如…

1.0 html(1)

html 一、基本介绍 1、定义:html是一种超文本标记语言,也是一种标识性语言(不是编程语言) 标记:记号(绰号) 超文本:就是页面内容可以包含图片、链接,音乐&#xff0c…

【软考】设计模式之状态模式

目录 1. 说明2. 应用场景3. 结构图4. 构成5. 优缺点5.1 优点5.2 缺点 6. java示例6.1 非状态模式6.1.1 问题分析6.1.2 接口类6.1.2 实现类6.1.3 客户端6.1.4 结果截图 6.2 状态模式6.2.1 抽象状态类6.2.2 状态类6.2.3 上下文类6.2.4 上下文类 1. 说明 1.允许一个对象在其内部状…

pycharm使用远程服务器的jupyter环境

1、确保服务器上安装了jupyter,如果没有,执行下面命令安装 pip install jupyter2、启动jupyter notebook服务 jupyter notebook --no-browser --port8888 --ip0.0.0.0 --allow-root表明在服务器的8888 端口上启动 Jupyter Notebook,并允许从任何 IP 地…

阿里云ESC云服务器搭建手册

1.开通阿里云ESC云服务 1.1 打开阿里云官网 https://www.aliyun.com/ 自行注册登录 1.2 选择产品 1.3 点击免费试用 新用户可以免费试用3个月 1.4 选择服务器配置 1.5 选择操作系统 创建服务器实例的时候会自动帮我们创建一个操作系统 1.6 点击立即试用 1.7 创建成功后点击前往…

鸿蒙HarmonyOS应用开发——组件级配置

在开发应用时,需要配置应用的一些标签,例如应用的包名、图标等标识特征的属性。本文描述了在开发应用需要配置的一些关键标签。 应用包名配置 应用需要在工程的AppScope目录下的 app.json5配置文件 中配置bundleName标签,该标签用于标识应用…

《MobileFaceNet:一种用于移动设备实时人脸验证的高效CNN》论文阅读

最近正好做到人脸识别的一点工作,在查阅资料的时候看到了这篇文章,就想花点时间来读一下。这里是自己的阅读记录,英语水平不够借助翻译软件来读的,感兴趣可以看下,也可以自行阅读原始英文论文。 摘要 我们提出了一类非…