自动超参数优化 AutoGluon 简单使用

自动超参数优化 AutoGluon 简单使用,第1张

自动超参数优化 AutoGluon 简单使用 今天发现 一个非常简单易用的超参数优化包 (李沐大神开发的),简单的使用了以下,效果不错。 说明

支持的模型
机器学习模型;
深度学习模型;
模型集成;
深度学习模型集成;
等等

简单应用

Autogluon官网:https://auto.gluon.ai/stable/index.html
使用kaggle 泰坦尼克号 公开数据集:https://www.kaggle.com/c/titanic/
代码和数据我整理放到了github: https://github.com/yinboliu-git/MachineLearning-sample-demos/tree/main/automl

安装(建议使用conda虚拟环境):
python3.7,3.8

pip install "mxnet<2.0.0"
pip install autogluon

代码(run.py):

#! /usr/bin/python3
from autogluon.tabular import TabularDataset, TabularPredictor
import pandas as pd
train_data = TabularDataset('train.csv').iloc[0:10,:]  # 因为模型时间长,这里只用前10个数据做测试
id, label = 'PassengerId', 'Survived'
predictor = TabularPredictor(label=label).fit(train_data.drop(columns=[id]))

test_data = TabularDataset('test.csv')
pred = predictor.predict(test_data.drop(columns=[id]))
sub = pd.Dataframe({id:test_data[id], label:pred})
sub.to_csv('submission.csv', index=False)

会自动生成模型保存在:./AutogluonModels

超参数调优

// 你没看错,这个里也要超参数调优。 哈哈哈,用于调优模型的模型也是有参数的:

使用:

time_limit = 60  # for quick demonstration only, you should set this to longest time you are willing to wait (in seconds)
metric = 'roc_auc'  # specify your evaluation metric here
predictor = TabularPredictor(label, eval_metric=metric).fit(train_data, time_limit=time_limit, presets='best_quality')
predictor.leaderboard(test_data, silent=True)

参数说明:
百度翻译:

此命令实施以下策略以最大限度地提高准确性:

1. 指定参数presets='best_quality',它允许 AutoGluon 基于stacking/ bagging 自动构建强大的模型集成,并且如果给予足够的训练时间,将大大改善结果预测。的默认值presets是 'medium_quality_faster_train',这会产生不太准确的模型,但有助于更快地进行原型设计。使用presets,您可以灵活地优先考虑预测准确性与训练/推理速度。例如,如果您不太关心预测性能并希望快速部署基本模型,请考虑使用: 。presets=['good_quality_faster_inference_only_refit', 'optimize_for_deployment']

2. 提供eval_metric,如果你知道什么指标将用来评估你的应用程序的预测。您可能使用的其他一些非默认指标包括:('f1'用于二元分类)、'roc_auc'(用于二元分类)、 'log_loss'(用于分类)、'mean_absolute_error'(用于回归)、'median_absolute_error'(用于回归)。您还可以定义自己的自定义度量函数,请参阅文件夹中的示例:autogluon/core/metrics/

3. 包括您的所有数据,train_data但不提供 tuning_data(AutoGluon 将更智能地拆分数据以满足其需求)。

4. 不要指定hyperparameter_tune_kwargs参数(与直觉相反,超参数调整不是花费有限训练时间预算的最佳方式,因为模型集成通常更优)。我们建议您仅hyperparameter_tune_kwargs 在您的目标是部署单个模型而不是集成时使用。

5. 不要指定hyperparameters参数(允许 AutoGluon 自适应地选择要使用的模型/超参数)。

6. 设置time_limit为您愿意等待的最长时间(以秒为单位)。AutoGluon 的预测性能提高了fit()允许运行的时间越长。

原文:

This command implements the following strategy to maximize accuracy:

Specify the argument presets='best_quality', which allows AutoGluon to automatically construct powerful model ensembles based on stacking/bagging, and will greatly improve the resulting predictions if granted sufficient training time. The default value of presets is 'medium_quality_faster_train', which produces less accurate models but facilitates faster prototyping. With presets, you can flexibly prioritize predictive accuracy vs. training/inference speed. For example, if you care less about predictive performance and want to quickly deploy a basic model, consider using: presets=['good_quality_faster_inference_only_refit', 'optimize_for_deployment'].

Provide the eval_metric if you know what metric will be used to evaluate predictions in your application. Some other non-default metrics you might use include things like: 'f1' (for binary classification), 'roc_auc' (for binary classification), 'log_loss' (for classification), 'mean_absolute_error' (for regression), 'median_absolute_error' (for regression). You can also define your own custom metric function, see examples in the folder: autogluon/core/metrics/

Include all your data in train_data and do not provide tuning_data (AutoGluon will split the data more intelligently to fit its needs).

Do not specify the hyperparameter_tune_kwargs argument (counterintuitively, hyperparameter tuning is not the best way to spend a limited training time budgets, as model ensembling is often superior). We recommend you only use hyperparameter_tune_kwargs if your goal is to deploy a single model rather than an ensemble.

Do not specify hyperparameters argument (allow AutoGluon to adaptively select which models/hyperparameters to use).

Set time_limit to the longest amount of time (in seconds) that you are willing to wait. AutoGluon’s predictive performance improves the longer fit() is allowed to run.

接说明

支持的任务
分类回归
图像识别
图像预测
物体检测
文本预测
多任务预测

另外
支持自定义模型
支持神经架构

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5689506.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存