跳到内容

自动化机器学习

Ludwig AutoML 接收一个数据集、目标列和一个时间预算,然后返回一个训练好的 Ludwig 模型。

Ludwig AutoML 目前处于实验阶段,主要专注于表格数据集。一篇描述其开发、评估和使用的博客文章在此

Ludwig AutoML 推断输入和输出特征的类型,选择模型架构,并在指定时间预算的限制下,启动一个跨一组超参数和范围的 Ray Tune Async HyperBand 搜索任务。它返回搜索试验生成的模型集合,按从优到劣排序,同时提供超参数搜索报告,该报告可以手动检查或由各种 Ludwig 可视化工具进行后处理。

用户可以通过以下描述的各种方式来审计和与 Ludwig AutoML 进行交互。

auto_train

Ludwig AutoML 的基本 API 是 auto_train。可以在此处找到其调用的简单示例。

import logging
import pprint

from ludwig.automl import auto_train
from ludwig.datasets import mushroom_edibility
from ludwig.utils.dataset_utils import get_repeatable_train_val_test_split

mushroom_df = mushroom_edibility.load()
mushroom_edibility_df = get_repeatable_train_val_test_split(mushroom_df, 'class', random_seed=42)

auto_train_results = auto_train(
    dataset=mushroom_edibility_df,
    target='class',
    time_limit_s=7200,
    tune_for_memory=False,
    user_config={'preprocessing': {'split': {'column': 'split', 'type': 'fixed'}}},
)

pprint.pprint(auto_train_results)

create_auto_config

Ludwig AutoML 的 create_auto_config API 输出 auto_train 的超参数搜索配置,但不运行搜索。此 API 对于检查 AutoML 选择的输入和输出特征类型、模型架构以及超参数和范围非常有用。其调用的简单示例

import logging
import pprint

from ludwig.automl import create_auto_config
from ludwig.datasets import mushroom_edibility
from ludwig.utils.dataset_utils import get_repeatable_train_val_test_split

mushroom_df = mushroom_edibility.load()
mushroom_edibility_df = get_repeatable_train_val_test_split(mushroom_df, 'class', random_seed=42)

auto_config = create_auto_config(
    dataset=mushroom_edibility_df,
    target='class',
    time_limit_s=7200,
    tune_for_memory=False,
    user_config={'preprocessing': {'split': {'column': 'split', 'type': 'fixed'}}},
)

pprint.pprint(auto_config)

来源

此 API 也适用于手动优化 AutoML 生成的搜索配置;此 API 的输出可以编辑,然后直接用作 Ludwig 超参数搜索任务的输入配置。

使用 user_config 覆盖自动配置

可以将 user_config 参数提供给 auto_traincreate_auto_config API,以覆盖生成的配置中指定的某些部分。

例如,我们可以指定 Walmart Recruiting 数据集的 TripType 输出特征类型应设置为 category,以覆盖 Ludwig AutoML 类型检测系统将该特征识别为 number 特征的判断。

import logging
import pprint

from ludwig.automl import auto_train
from ludwig.datasets import walmart_recruiting
from ludwig.utils.dataset_utils import get_repeatable_train_val_test_split

walmart_df = walmart_recruiting.load()
walmart_recruiting_df = get_repeatable_train_val_test_split(walmart_df, 'TripType', random_seed=42)

auto_train_results = auto_train(
    dataset=walmart_recruiting_df,
    target='TripType',
    time_limit_s=3600,
    tune_for_memory=False,
    user_config={'output_features': [{'column': 'TripType', 'name': 'TripType', 'type': 'category'}],
        'preprocessing': {'split': {'column': 'split', 'type': 'fixed'}}},
)

pprint.pprint(auto_train_results)

来源

我们还可以指定超参数搜索任务优化指定输出特征的最大准确率,而不是默认情况下优化所有组合输出特征的最小损失。

import logging
import pprint

from ludwig.automl import auto_train
from ludwig.datasets import mushroom_edibility
from ludwig.utils.dataset_utils import get_repeatable_train_val_test_split

mushroom_df = mushroom_edibility.load()
mushroom_edibility_df = get_repeatable_train_val_test_split(mushroom_df, 'class', random_seed=42)

auto_train_results = auto_train(
    dataset=mushroom_edibility_df,
    target='class',
    time_limit_s=3600,
    tune_for_memory=False,
    user_config={'hyperopt': {'goal': 'maximize', 'metric': 'accuracy', 'output_feature': 'class'},
        'preprocessing': {'split': {'column': 'split', 'type': 'fixed'}}},
)

pprint.pprint(auto_train_results)

来源