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

2024-03-27 18:28

本文主要是介绍【AutoML】一个用于图像、文本、时间序列和表格数据的AutoML,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一个用于图像、文本、时间序列和表格数据的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/cu118pip 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 MBTrain 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 runtime17 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   runtime0.02s	 = Validation runtime
Fitting model: KNeighborsDist ...0.2132	 = Validation score   (accuracy)0.04s	 = Training   runtime0.02s	 = Validation runtime
Fitting model: NeuralNetFastAI ...0.9459	 = Validation score   (accuracy)21.81s	 = Training   runtime0.02s	 = Validation runtime
Fitting model: LightGBMXT ...0.9459	 = Validation score   (accuracy)8.91s	 = Training   runtime0.21s	 = Validation runtime
Fitting model: LightGBM ...0.956	 = Validation score   (accuracy)6.37s	 = Training   runtime0.12s	 = Validation runtime
Fitting model: RandomForestGini ...0.9449	 = Validation score   (accuracy)5.6s	 = Training   runtime0.09s	 = Validation runtime
Fitting model: RandomForestEntr ...0.9499	 = Validation score   (accuracy)6.36s	 = Training   runtime0.1s	 = Validation runtime
Fitting model: CatBoost ...0.956	 = Validation score   (accuracy)57.69s	 = Training   runtime0.01s	 = Validation runtime
Fitting model: ExtraTreesGini ...0.9469	 = Validation score   (accuracy)2.16s	 = Training   runtime0.11s	 = Validation runtime
Fitting model: ExtraTreesEntr ...0.9429	 = Validation score   (accuracy)2.06s	 = Training   runtime0.16s	 = Validation runtime
Fitting model: XGBoost ...0.957	 = Validation score   (accuracy)11.36s	 = Training   runtime0.36s	 = Validation runtime
Fitting model: NeuralNetTorch ...0.9409	 = Validation score   (accuracy)41.09s	 = Training   runtime0.01s	 = Validation runtime
Fitting model: LightGBMLarge ...0.9499	 = Validation score   (accuracy)12.24s	 = Training   runtime0.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   runtime0.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

这篇关于【AutoML】一个用于图像、文本、时间序列和表格数据的AutoML的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/852989

相关文章

大模型研发全揭秘:客服工单数据标注的完整攻略

在人工智能(AI)领域,数据标注是模型训练过程中至关重要的一步。无论你是新手还是有经验的从业者,掌握数据标注的技术细节和常见问题的解决方案都能为你的AI项目增添不少价值。在电信运营商的客服系统中,工单数据是客户问题和解决方案的重要记录。通过对这些工单数据进行有效标注,不仅能够帮助提升客服自动化系统的智能化水平,还能优化客户服务流程,提高客户满意度。本文将详细介绍如何在电信运营商客服工单的背景下进行

基于MySQL Binlog的Elasticsearch数据同步实践

一、为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品、订单等数据的多维度检索。 使用 Elasticsearch 存储业务数据可以很好的解决我们业务中的搜索需求。而数据进行异构存储后,随之而来的就是数据同步的问题。 二、现有方法及问题 对于数据同步,我们目前的解决方案是建立数据中间表。把需要检索的业务数据,统一放到一张M

服务器集群同步时间手记

1.时间服务器配置(必须root用户) (1)检查ntp是否安装 [root@node1 桌面]# rpm -qa|grep ntpntp-4.2.6p5-10.el6.centos.x86_64fontpackages-filesystem-1.41-1.1.el6.noarchntpdate-4.2.6p5-10.el6.centos.x86_64 (2)修改ntp配置文件 [r

关于数据埋点,你需要了解这些基本知识

产品汪每天都在和数据打交道,你知道数据来自哪里吗? 移动app端内的用户行为数据大多来自埋点,了解一些埋点知识,能和数据分析师、技术侃大山,参与到前期的数据采集,更重要是让最终的埋点数据能为我所用,否则可怜巴巴等上几个月是常有的事。   埋点类型 根据埋点方式,可以区分为: 手动埋点半自动埋点全自动埋点 秉承“任何事物都有两面性”的道理:自动程度高的,能解决通用统计,便于统一化管理,但个性化定

基于人工智能的图像分类系统

目录 引言项目背景环境准备 硬件要求软件安装与配置系统设计 系统架构关键技术代码示例 数据预处理模型训练模型预测应用场景结论 1. 引言 图像分类是计算机视觉中的一个重要任务,目标是自动识别图像中的对象类别。通过卷积神经网络(CNN)等深度学习技术,我们可以构建高效的图像分类系统,广泛应用于自动驾驶、医疗影像诊断、监控分析等领域。本文将介绍如何构建一个基于人工智能的图像分类系统,包括环境

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

异构存储(冷热数据分离)

异构存储主要解决不同的数据,存储在不同类型的硬盘中,达到最佳性能的问题。 异构存储Shell操作 (1)查看当前有哪些存储策略可以用 [lytfly@hadoop102 hadoop-3.1.4]$ hdfs storagepolicies -listPolicies (2)为指定路径(数据存储目录)设置指定的存储策略 hdfs storagepolicies -setStoragePo

Hadoop集群数据均衡之磁盘间数据均衡

生产环境,由于硬盘空间不足,往往需要增加一块硬盘。刚加载的硬盘没有数据时,可以执行磁盘数据均衡命令。(Hadoop3.x新特性) plan后面带的节点的名字必须是已经存在的,并且是需要均衡的节点。 如果节点不存在,会报如下错误: 如果节点只有一个硬盘的话,不会创建均衡计划: (1)生成均衡计划 hdfs diskbalancer -plan hadoop102 (2)执行均衡计划 hd

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

烟火目标检测数据集 7800张 烟火检测 带标注 voc yolo

一个包含7800张带标注图像的数据集,专门用于烟火目标检测,是一个非常有价值的资源,尤其对于那些致力于公共安全、事件管理和烟花表演监控等领域的人士而言。下面是对此数据集的一个详细介绍: 数据集名称:烟火目标检测数据集 数据集规模: 图片数量:7800张类别:主要包含烟火类目标,可能还包括其他相关类别,如烟火发射装置、背景等。格式:图像文件通常为JPEG或PNG格式;标注文件可能为X