autogluon.tabular.models

注意

本文档适用于高级用户,且内容并不全面。

有关稳定的公共API,请参考TabularPredictor。

模型键

要使用TabularPredictor拟合模型,您必须在TabularPredictor.fithyperparameters参数中指定它。

hyperparameters 接受一个模型字典,其中每个键是模型名称,值是一个模型超参数的字典列表。

例如:

以下是键到模型的映射:

以下是模型类型在训练时与其默认名称的映射:

模型名称后缀

由TabularPredictor训练的模型在其名称中可能包含具有特殊含义的后缀。

后缀如下:

“_Lx”: 表示模型训练的堆栈级别(x),例如“_L1”、“_L2”等。 带有“_L1”后缀的模型是基础模型,意味着它不依赖于任何其他模型。 如果模型缺少此后缀,则它是一个基础模型,并且处于级别1(“_L1”)。

“/Tx”: 表示该模型是通过超参数搜索(HPO)训练的。Tx 是 HPO 试验 #x 的简写。 一个例子是 “LightGBM/T8”

“_BAG”: 表示该模型是一个打包集成模型。 打包集成模型包含多个模型实例(子模型),这些子模型使用不同的数据子集进行训练。 在推理过程中,这些子模型分别对数据进行预测,并将它们的预测结果在最终结果中进行平均。 这通常比任何单个模型单独使用都能获得更强的结果, 但会显著降低推理速度。有关如何提高推理速度的说明,请参考“_FULL”

“_FULL”: 表示该模型已通过TabularPredictor的refit_full方法重新拟合。 此模型将没有验证分数,因为所有数据(训练和验证)都被用作训练数据。 通常,会有另一个模型与此模型同名,但没有“_FULL”后缀。 通常,由于在训练过程中使用了更多数据,此模型可以优于原始模型, 但如果原始模型是bagged ensemble(“_BAG”),则通常较弱,但推理速度要快得多。

“_DSTL”: 表示该模型是通过调用TabularPredictor的distill方法进行模型蒸馏创建的。蒸馏模型的验证分数应仅与其他蒸馏模型进行比较。

“_x”: 表示没有添加此后缀的名称已经在另一个模型中存在,因此添加此后缀以避免覆盖预先存在的模型。一个例子是“LightGBM_2”

模型

AbstractModel

所有AutoGluon模型继承的抽象模型实现。

LGBModel

LightGBM 模型: https://lightgbm.readthedocs.io/en/latest/

CatBoostModel

CatBoost 模型: https://catboost.ai/

XGBoostModel

XGBoost 模型: https://xgboost.readthedocs.io/en/latest/

RFModel

随机森林模型 (scikit-learn): https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html

XTModel

Extra Trees模型 (scikit-learn): https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.ExtraTreesClassifier.html#sklearn.ensemble.ExtraTreesClassifier

KNNModel

K近邻模型 (scikit-learn): https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html

LinearModel

线性模型(scikit-learn):https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html

TabularNeuralNetTorchModel

用于分类/回归的PyTorch神经网络模型,适用于表格数据。

NNFastAiTabularModel

用于处理表格数据的fastai v1神经网络模型的类。

VowpalWabbitModel

VowpalWabbit 模型: https://vowpalwabbit.org/

MultiModalPredictorModel

TextPredictorModel

不使用图像特征的多模态预测器

ImagePredictorModel

仅使用图像特征的MultimodalPredictor。目前仅支持1个图像列,每个样本有1张图像。此外,具有特殊的空图像处理功能,以提高在存在空图像(即图像路径为'')时的性能。注意:空图像处理尚未与MultimodalPredictor内置的空图像处理进行比较。

AbstractModel

class autogluon.tabular.models.AbstractModel(path: str = None, name: str = None, problem_type: str = None, eval_metric: str | Scorer = None, hyperparameters: dict = None)[source]

所有AutoGluon模型继承的抽象模型实现。

Parameters:
  • path (str, default = None) – 存储所有输出的目录位置。 如果为None,则选择一个新的唯一时间戳目录。

  • name (str, default = None) – 模型将保存的路径内的子目录名称。 最终的模型目录将是 os.path.join(path, name) 如果为 None,则默认为模型的类名:self.__class__.__name__

  • problem_type (str, default = None) – 预测问题的类型,即这是一个二元/多元分类还是回归问题(选项:‘binary’,‘multiclass’,‘regression’)。 如果为None,将在训练期间尝试根据训练数据标签推断问题类型。

  • eval_metric (autogluon.core.metrics.Scorer 或 str, 默认 = None) –

    用于在测试数据上最终评估预测结果的指标。 这只会影响 model.score(),因为在训练过程中不会使用 eval_metric。

    如果 eval_metric = None,它将根据 problem_type 自动选择。 对于二分类和多分类问题,默认值为‘accuracy’,对于回归问题,默认值为‘root_mean_squared_error’。 否则,分类问题的选项为:

    [‘accuracy’, ‘balanced_accuracy’, ‘f1’, ‘f1_macro’, ‘f1_micro’, ‘f1_weighted’, ‘roc_auc’, ‘roc_auc_ovo’, ‘roc_auc_ovr’, ‘average_precision’, ‘precision’, ‘precision_macro’, ‘precision_micro’, ‘precision_weighted’, ‘recall’, ‘recall_macro’, ‘recall_micro’, ‘recall_weighted’, ‘log_loss’, ‘pac_score’, ‘quadratic_kappa’]

    回归问题的选项:

    [‘root_mean_squared_error’, ‘mean_squared_error’, ‘mean_absolute_error’, ‘median_absolute_error’, ‘r2’]

    分位数回归的选项:

    [‘pinball_loss’]

    有关这些选项的更多信息,请参阅 sklearn.metrics: https://scikit-learn.org/stable/modules/classes.html#sklearn-metrics-metrics

    你也可以在这里传递你自己的评估函数,只要它遵循 autogluon.core.metrics 文件夹中定义的函数的格式。

  • 超参数 – 模型将使用的超参数(可以是搜索空间而不是固定值)。 如果为None,则使用模型默认值。这与传递空字典相同。

can_compile(compiler_configs: dict = None) bool[source]

验证模型是否可以使用编译器配置进行编译。

Parameters:

compiler_configs (dict, default=None) – 模型特定的编译器选项。 这对于指定特定模型的编译器后端非常有用, 例如 {“RandomForest”: {“compiler”: “onnx”}}

can_estimate_memory_usage_static() bool[source]

如果为这个模型实现了estimate_memory_usage_static,则为True。 如果为False,调用estimate_memory_usage_static将引发NotImplementedError。

can_estimate_memory_usage_static_child() bool[source]

如果为这个模型的子类实现了estimate_memory_usage_static,则为True。 如果为False,调用estimate_memory_usage_static_child将引发NotImplementedError。

can_fit() bool[source]

如果模型可以拟合,则返回True。

can_infer() bool[source]

如果模型能够对新数据进行推理,则返回True。

can_predict_proba() bool[source]

如果模型可以预测概率,则返回True。

compile(compiler_configs: dict = None)[source]

编译训练好的模型以加快推理速度。

注意: - 假定模型在编译之前已经拟合。 - 如果编译器的 save_in_pkl 属性为 False,self.model 将被设置为 None。

Parameters:

compiler_configs (dict, default=None) – 模型特定的编译器选项。 这对于为特定模型指定编译器后端非常有用, 例如 {“RandomForest”: {“compiler”: “onnx”}}

compute_feature_importance(X: DataFrame, y: Series, features: List[str] = None, silent: bool = False, importance_as_list: bool = False, **kwargs) DataFrame[source]

通过排列洗牌计算特征重要性。

Parameters:
  • X

  • y

  • 特性

  • 静默

  • importance_as_list

  • kwargs

Return type:

特征重要性的pd.DataFrame

convert_to_refit_full_template()[source]

调用此函数后,返回的模型应该能够在没有X_val、y_val的情况下使用原始模型训练的迭代进行拟合。

将max_memory_usage_ratio增加25%,以减少重新拟合模型触发NotEnoughMemoryError并跳过训练的可能性。 如果不增加25%,这种情况可能会发生,因为重新拟合模型通常会使用更多的训练数据,因此需要更多的内存。

convert_to_refit_full_via_copy()[source]

创建一个新的refit_full模型变体,但不是通过训练,而是简单地复制self。 此方法用于与尚未实现refit_full支持的模型兼容,作为备用方案。

convert_to_template()[source]

调用此函数后,返回的模型应该能够像新模型一样进行拟合,并且可以进行深度复制。 模型名称和路径将与原始模型相同,必须在训练之前重命名,以避免覆盖已存在的原始模型文件。

delete_from_disk(silent: bool = False)[source]

从磁盘删除模型。

警告:这将删除self.path目录中的所有文件,无论它们是否由AutoGluon创建。 请勿在模型目录中存储与AutoGluon无关的文件。

estimate_memory_usage(X: DataFrame, **kwargs) int[source]

估计模型在训练期间的峰值内存使用量。

Parameters:

X (pd.DataFrame) – 训练数据的特征

Returns:

整数

Return type:

训练期间估计的峰值内存使用量(以字节为单位)

estimate_memory_usage_child(X: DataFrame, **kwargs) int[source]

估计子模型在训练期间的峰值内存使用量。

如果模型不是一个打包模型(即没有子模型),那么将返回其个人内存使用估计。

Parameters:
  • X (pd.DataFrame) – 训练数据的特征

  • **kwargs

Returns:

整数

Return type:

训练子模型期间的估计峰值内存使用量(以字节为单位)

classmethod estimate_memory_usage_static(*, X: DataFrame, y: Series = None, hyperparameters: dict = None, problem_type: str = 'infer', num_classes: int | None | str = 'infer', **kwargs) int[source]

估计模型在训练期间的峰值内存使用量,而无需初始化模型。

Parameters:
  • X (pd.DataFrame) – 训练数据的特征

  • y (pd.Series, 可选) – 训练数据的真实值。如果未指定 problem_type 或 num_classes,则必须指定。

  • 超参数 (dict, 可选) – 模型的超参数

  • problem_type (str, default = "infer") – 问题类型。如果为“infer”,将根据y进行推断。

  • num_classes – num_classes。如果为“infer”,将根据y推断。

  • **kwargs – 其他可选的关键字参数,可能会影响模型的内存使用。

Returns:

整数

Return type:

训练期间估计的峰值内存使用量(以字节为单位)

estimate_memory_usage_static_child(*, X: DataFrame, y: Series = None, hyperparameters: dict = None, problem_type: str = 'infer', num_classes: int | None | str = 'infer', **kwargs) int[source]

估计子模型在训练期间的峰值内存使用量,而无需初始化模型。

请注意,此方法本身不是静态的,因为子模型必须作为模型中的变量存在,才能调用其静态内存估计方法。

要以完全静态的方式获取子内存估计,可以直接调用子对象的estimate_memory_usage_static方法。

Parameters:
  • X (pd.DataFrame) – The training data features

  • y (pd.Series, 可选) – 训练数据的真实值。如果未指定 problem_type 或 num_classes,则必须指定。

  • 超参数 (dict, 可选) – 模型的超参数

  • problem_type (str, default = "infer") – 问题类型。如果为“infer”,将根据y进行推断。

  • num_classes – The num_classes. If “infer” will infer based on y.

  • **kwargs – 其他可能影响模型内存使用的可选关键字参数。

Returns:

整数

Return type:

训练子模型期间的估计峰值内存使用量(以字节为单位)

fit(**kwargs)[source]

拟合模型以基于X预测y中的值。

模型不应覆盖fit方法,而应覆盖具有相同参数的_fit方法。

Parameters:
  • X (DataFrame) – 训练数据的特征。

  • y (Series) – 训练数据的真实标签。

  • X_val (DataFrame, default = None) – 验证数据的特征。 如果为None,则通过验证分数进行的早停将被禁用。

  • y_val (Series, default = None) – 验证数据的真实标签。 如果为None,则通过验证分数进行的早停将被禁用。

  • X_test (DataFrame, 默认 = None) – 测试数据的特征。注意:不用于训练,但用于跟踪测试性能。 如果为None,则通过验证分数进行的早停将被禁用。

  • y_test (Series, default = None) – 测试数据的真实标签。注意:不用于训练,但用于跟踪测试性能。 如果为None,则通过验证分数进行的早停将被禁用。

  • X_unlabeled (DataFrame, default = None) – 未标记的数据特征。 模型可以选择性地实现利用未标记数据来提高模型准确性的逻辑。

  • time_limit (float, default = None) – 拟合模型时遵守的时间限制(以秒为单位)。 理想情况下,如果指定了时间限制,模型应在拟合过程中提前停止,以避免超过时间限制。

  • sample_weight (Series, default = None) – 训练数据的样本权重。 模型在拟合过程中可以选择性地利用样本权重。 如果为None,则由模型决定。通常,模型假设样本权重是均匀的。

  • sample_weight_val (Series, default = None) – 验证数据的样本权重。 如果为None,则由模型决定。通常,模型假设样本权重是均匀的。

  • num_cpus (int, default = 'auto') – 在拟合过程中使用多少个CPU。 这是按虚拟核心计算的,而不是物理核心。 如果为‘auto’,则由模型决定。

  • num_gpus (int, default = 'auto') – 在拟合过程中使用多少个GPU。 如果为‘auto’,则由模型决定。

  • feature_metadata (autogluon.common.features.feature_metadata.FeatureMetadata, 默认 = None) – 包含特征类型信息,可用于识别特殊特征,如文本 ngrams 和日期时间,以及哪些特征是数值型与类别型。 如果为 None,则在拟合期间推断 feature_metadata。

  • verbosity (int, default = 2) – 详细程度级别从0到4,控制打印的信息量。 较高的级别对应更详细的打印信息(你可以设置 verbosity = 0 来抑制警告)。 verbosity 4: 记录每次训练迭代,并记录最详细的信息。 verbosity 3: 定期记录训练迭代,并记录更详细的信息。 verbosity 2: 仅记录重要信息。 verbosity 1: 仅记录警告和异常。 verbosity 0: 仅记录异常。

  • **kwargs – 模型支持的任何额外拟合参数。

property fit_num_cpus: int

拟合此模型时使用的CPU数量

property fit_num_cpus_child: int

用于拟合一个模型(即子模型)的CPU数量

property fit_num_gpus: float

拟合此模型时使用的GPU数量

property fit_num_gpus_child: float

用于拟合一个模型(即子模型)的GPU数量

get_fit_metadata() dict[source]

返回与模型拟合相关的元数据字典,这些元数据与超参数无关。 必须在模型拟合后调用。

get_info() dict[source]

返回一个包含描述模型的多个字段的字典。

get_memory_size(allow_exception: bool = False) int | None[source]

将模型对象(self)进行腌制并返回其大小(以字节为单位)。 如果self无法被腌制,将会引发异常。

注意:这将暂时使模型的内存使用量翻倍,因为原始版本和序列化版本都将存在于内存中。 如果模型大于剩余的可用内存,这可能会导致内存不足错误。

Parameters:

allow_exception (bool, default = False) – 如果为True,并且在内存大小计算期间发生异常,将返回None而不是引发异常。 例如,如果模型在拟合期间失败并且内部状态混乱,然后调用了get_memory_size, 它可能仍然包含一个不可序列化的对象。通过设置allow_exception=True,我们避免了在这种情况下崩溃。 例如:“AttributeError: 无法pickle本地对象‘func_generator..custom_metric’”

Returns:

memory_size – 序列化模型对象的内存大小,以字节为单位。 如果发生异常且allow_exception=True,则为None。

Return type:

整数 | 无

get_minimum_resources(is_gpu_available: bool = False) Dict[str, int | float][source]
Parameters:
  • is_gpu_available (bool, default = False) – 系统中是否可用GPU。 可以在CPU和GPU上训练的模型可以基于此决定最小资源。

  • model. (返回一个字典,包含拟合所需的最小资源要求)

  • train. (如果子类需要更多资源,应考虑重写此方法)

  • 字典 (如果资源不是输出的一部分)

  • 不必要的。 (被认为是)

  • keys (有效)

get_params() dict[source]

获取模型初始化时的参数

get_params_aux_info() dict[source]

将学习曲线评分器对象转换为其名称字符串。

返回:

params_aux 字典,包含更改后的 curve_metrics 字段(如果适用)。

get_trained_params() dict[source]

返回训练模型的超参数。 如果模型提前停止,这将包含模型在推理期间使用的周期/迭代,而不是在拟合期间指定的周期/迭代。 这用于生成模型模板以在所有数据上重新拟合(无验证集)。

hyperparameter_tune(hyperparameter_tune_kwargs='auto', hpo_executor: HpoExecutor = None, time_limit: float = None, **kwargs)[source]

执行模型的超参数调优,根据初始化时在hyperparameters中提供的搜索空间拟合模型的多个变体。

Parameters:
  • hyperparameter_tune_kwargs (strdict, 默认='auto') –

    超参数调优策略和参数(例如,要运行多少次HPO试验)。 有效键:

    ’num_trials’: 你想要执行的hpo试验次数。 ‘scheduler’: hpo实验使用的调度器。

    有效值:

    ’local’: 本地FIFO调度器。如果是自定义后端则为顺序执行,如果是Ray Tune后端则为并行执行。

    ’searcher’: hpo实验使用的搜索算法。
    有效值:

    ’auto’: 随机搜索。 ‘random’: 随机搜索。 ‘bayes’: 贝叶斯优化。仅支持Ray Tune后端。

    有效预设值:

    ’auto’: 使用‘random’预设。 ‘random’: 使用本地调度器通过随机搜索执行HPO。

    当提供字典时,‘searcher’键是必需的。

  • hpo_executor (HpoExecutor, default None) – 用于执行HPO实验的执行器。这实现了不同HPO后端的接口。 更多信息,请参考core/hpo/executors.py下的HpoExecutor

  • time_limit (float, default None) – 通常,这是运行HPO的时间限制(以秒为单位)。 实际上,这是HPO执行的所有试验完全训练的时间预算(以秒为单位)。 例如,BaggedEnsemble在HPO期间只会使用时间限制的一部分,因为它需要剩余的时间来拟合所有试验的折叠。

  • **kwargs

    与传递给fit调用的相同kwargs,例如:

    X y X_val y_val feature_metadata sample_weight sample_weight_val

Returns:

  • Tuple of (hpo_results (Dict[str, dict], hpo_info: Any))

  • hpo_results (Dict[str, dict]) –

    一个字典,键为试验模型名称,值为包含以下内容的字典:
    path: str

    训练模型产物的绝对路径。用于加载模型。

    val_score: float

    模型的val_score

    trial: int

    模型的试验编号,从0开始。

    hyperparameters: dict

    模型试验的超参数配置。

  • hpo_info (Any) – 包含调度器特定逻辑的高级输出,主要用于调试。 在Ray Tune后端的情况下,这将是一个Analysis对象:https://docs.ray.io/en/latest/tune/api/doc/ray.tune.ExperimentAnalysis.html

is_fit() bool[source]

如果模型已经拟合,则返回 True。

is_initialized() bool[source]

如果模型已初始化,则返回True。 这表明模型是否已经推断出各种信息,如problem_type和num_classes。 当调用.fit.hyperparameter_tune时,模型会自动初始化。

is_valid() bool[source]

如果模型能够对新数据进行推理(如果是普通模型)或已经产生了折叠外预测(如果是打包模型),则返回True 这表明该模型是否可以用作基础模型来拟合堆叠集成模型。

classmethod load(path: str, reset_paths: bool = True, verbose: bool = True)[source]

将模型从磁盘加载到内存中。

Parameters:
  • path (str) – 保存模型的路径,不包括文件名。 这通常应该是一个以‘/’字符结尾的目录路径(或根据操作系统适当的路径分隔符值)。 模型文件通常位于 os.path.join(path, cls.model_file_name)。

  • reset_paths (bool, default True) – 是否将加载模型的self.path值重置为等于path。 强烈建议将此值保持为True,除非访问原始的self.path值很重要。 如果为False,实际的有效路径和self.path可能会不同,导致模型在以后需要加载任何其他文件时出现奇怪的行为和潜在的异常。

  • verbose (bool, 默认 True) – 是否记录加载文件的位置。

Returns:

model – 已加载的模型对象。

Return type:

cls

classmethod load_learning_curves(path: str) List[source]

从磁盘加载learning_curve数据到内存。

Parameters:

path (str) – 保存模型的路径,不包括文件名。 这通常应该是一个以‘/’字符结尾的目录路径(或根据操作系统适当的路径分隔符值)。 模型文件通常位于 os.path.join(path, cls.model_file_name)。

Returns:

learning_curves – 已加载的学习曲线数据。

Return type:

列表

predict(X, **kwargs) ndarray[source]

返回X的类别预测。 对于二分类和多分类问题,这将返回预测的类别标签作为一维numpy数组。 对于回归问题,这将返回预测值作为一维numpy数组。

predict_from_proba(y_pred_proba: ndarray) ndarray[source]

将预测概率转换为预测结果。

Parameters:

y_pred_proba (np.ndarray) – 需要转换为预测的预测概率。

Returns:

y_pred – 从y_pred_proba获得的预测结果。

Return type:

np.ndarray

示例

>>> y_pred = predictor.predict(X)
>>> y_pred_proba = predictor.predict_proba(X)
>>>
>>> # Identical to y_pred
>>> y_pred_from_proba = predictor.predict_from_proba(y_pred_proba)
property predict_n_size: int | None

用于计算self.predict_time的数据中的行数。

property predict_n_time_per_row: float | None

在给定批量大小为self.predict_n_size的情况下,预测1行数据所需的时间(以秒为单位)。如果self.predict_timeself.predict_n_size为None,则返回None。

predict_proba(X, *, normalize: bool | None = None, record_time: bool = False, **kwargs) ndarray[source]

返回X的类别预测概率。 对于二分类问题,这将返回正类标签概率作为一维numpy数组。 对于多分类问题,这将返回每个类别的类别标签概率作为二维numpy数组。 对于回归问题,这将返回预测值作为一维numpy数组。

Parameters:
  • X – 用于预测的数据。

  • normalize (bool | None, default = None) – 是否在返回之前对预测进行归一化。 如果为None,将默认为self.normalize_pred_probas

  • record_time (bool, default = False) – 如果为True,将会记录预测所花费的时间在self.predict_time中,并记录X的行数在self.predict_n_size中。

  • kwargs – 传递给 self._predict_proba 的关键字参数。

Returns:

y_pred_proba – 预测概率

Return type:

np.ndarray

preprocess(X, preprocess_nonadaptive: bool = True, preprocess_stateful: bool = True, **kwargs)[source]

将输入数据预处理为适合拟合或推理的内部形式。 不建议重写此方法,因为它与多层堆叠逻辑紧密相关。相反,应重写_preprocess

record_predict_info(X: DataFrame)[source]

记录计算self.predict_n_time_per_row所需的信息。

Parameters:

X (pd.DataFrame) – 用于在计算self.predict_time时进行预测的数据。

reduce_memory_size(remove_fit: bool = True, remove_info: bool = False, requires_save: bool = True, **kwargs)[source]

从模型中移除非必要的对象以减少内存和磁盘占用。 如果remove_fit=True,则启用移除模型拟合所需的变量。如果模型已经完全训练,那么移除这些变量是安全的。 如果remove_info=True,则启用移除在model.get_info()期间使用的变量。调用model.get_info()时,这些值将为None。 如果requires_save=True,则启用移除属于model.pkl对象的变量,如果之前已经持久化,则需要将模型覆盖保存到磁盘。

模型不需要实现这个。

rename(name: str)[source]

重命名模型并更新self.path以反映更新后的名称。

save(path: str = None, verbose: bool = True) str[source]

将模型保存到磁盘。

Parameters:
  • path (str, default None) – 保存模型的路径,不包括文件名。 这通常应该是一个以‘/’字符结尾的目录路径(或根据操作系统适当的路径分隔符值)。 如果为None,则使用self.path。 最终的模型文件通常保存到os.path.join(path, self.model_file_name)。

  • verbose (bool, 默认值 True) – 是否记录保存文件的位置。

Returns:

path – 保存模型的路径,不包括文件名。 使用此值通过 cls.load(path) 从磁盘加载模型,cls 是模型对象的类,例如 model = RFModel.load(path)

Return type:

字符串

save_learning_curves(metrics: str | ~typing.List[str], curves: dict[dict[slice(<class 'str'>, typing.List[float], None)]], path: str = None) str[source]

将学习曲线保存到磁盘。

Outputted Curve Format:
out = [

指标, [

[ # log_loss

[0.693147, 0.690162, …], # 训练 [0.693147, 0.690162, …], # 验证 [0.693147, 0.690162, …], # 测试

], [ # 准确率

[0.693147, 0.690162, …], # 训练 [0.693147, 0.690162, …], # 验证 [0.693147, 0.690162, …], # 测试

], [ # f1

[0.693147, 0.690162, …], # 训练 [0.693147, 0.690162, …], # 验证 [0.693147, 0.690162, …], # 测试

],

]

]

Parameters:
  • metrics (strlist(str)) – 在曲线的每次迭代中计算的所有评估指标的列表

  • curves (dict[dict[str : list[float]]]) –

    评估集及其学习曲线字典的字典。 每个学习曲线字典包含每次迭代计算的评估指标。 例如:

    curves = {
    “train”: {

    ‘logloss’: [0.693147, 0.690162, …], ‘accuracy’: [0.500000, 0.400000, …], ‘f1’: [0.693147, 0.690162, …]

    }, “val”: {…}, “test”: {…},

    }

  • path (str, default None) – 学习曲线保存的路径,不包括文件名。 这通常应该是一个以‘/’字符(或根据操作系统适当的路径分隔符值)结尾的目录路径。 如果为None,则使用self.path。 最终的曲线文件通常保存到os.path.join(path, curves.json)。

Returns:

path – 保存曲线的路径,不包括文件名。

Return type:

字符串

validate_fit_resources(num_cpus='auto', num_gpus='auto', total_resources=None, **kwargs)[source]

验证提供的num_cpus和num_gpus(如果未提供则使用默认值)是否足以训练模型。如果不足,则引发AssertionError。

LGBModel

class autogluon.tabular.models.LGBModel(**kwargs)[source]

LightGBM model: https://lightgbm.readthedocs.io/en/latest/

超参数选项:https://lightgbm.readthedocs.io/en/latest/Parameters.html

Extra hyperparameter options:

ag.early_stop : int, 指定提前停止的轮数。默认为自适应策略。建议保持默认。

CatBoost模型

class autogluon.tabular.models.CatBoostModel(**kwargs)[source]

CatBoost model: https://catboost.ai/

超参数选项:https://catboost.ai/en/docs/references/training-parameters

XGBoost模型

class autogluon.tabular.models.XGBoostModel(**kwargs)[source]

XGBoost model: https://xgboost.readthedocs.io/en/latest/

超参数选项:https://xgboost.readthedocs.io/en/latest/parameter.html

RFModel

class autogluon.tabular.models.RFModel(**kwargs)[source]

Random Forest model (scikit-learn): https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html

XTModel

class autogluon.tabular.models.XTModel(**kwargs)[source]

Extra Trees model (scikit-learn): https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.ExtraTreesClassifier.html#sklearn.ensemble.ExtraTreesClassifier

KNN模型

class autogluon.tabular.models.KNNModel(**kwargs)[source]

KNearestNeighbors model (scikit-learn): https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html

线性模型

class autogluon.tabular.models.LinearModel(**kwargs)[source]

Linear model (scikit-learn): https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html

模型后端根据 problem_type 的不同而有所不同:

表格神经网络Torch模型

class autogluon.tabular.models.TabularNeuralNetTorchModel(**kwargs)[source]

用于分类/回归的PyTorch神经网络模型,适用于表格数据。

Extra hyperparameter options:
ag.early_stopint | str, default = “default”

指定提前停止的轮数。默认为自适应策略。建议保持默认。

NNFastAiTabularModel

class autogluon.tabular.models.NNFastAiTabularModel(**kwargs)[source]

用于处理表格数据的fastai v1神经网络模型的类。

Hyperparameters:

‘y_scaler’:在回归问题上,模型可能会对未见过的数据给出不合理的预测。 为了解决这个问题,AutoGluon 默认对回归问题的 y 值进行缩放。 此属性允许为 y 值传递自定义的缩放器。请注意,中间 迭代指标将受到此变换的影响,因此中间迭代分数将与 最终分数不同(最终分数将是正确的)。 https://scikit-learn.org/stable/modules/classes.html#module-sklearn.preprocessing

‘clipping’:在回归问题中,y的极端异常值可能会在训练期间和未见数据上损害模型的性能。为了解决这个问题,AutoGluon默认会将输入的y值和输出预测值裁剪到从训练数据推断出的范围内。将此属性设置为False将禁用裁剪。

‘layers’: 隐藏层大小的列表;None - 使用模型的启发式方法;默认值为 None

‘emb_drop’: 嵌入层 dropout;默认值为 0.1

‘ps’: 线性层的dropout - 应用于layers中每一层的值列表;默认值为[0.1]

‘bs’: 批量大小;默认值为256

‘lr’: 单周期策略的最大学习率;默认值为1e-2; 另见 https://docs.fast.ai/callback.schedule.html#Learner.fit_one_cycle, 单周期策略论文: https://arxiv.org/abs/1803.09820

‘epochs’: 训练轮数;默认值为30

# 早停设置。更多详情请参见:https://docs.fast.ai/callback.tracker.html#EarlyStoppingCallback ‘early.stopping.min_delta’: 0.0001, ‘early.stopping.patience’: 10,

VowpalWabbitModel

class autogluon.tabular.models.VowpalWabbitModel(**kwargs)[source]

VowpalWabbit Model: https://vowpalwabbit.org/

VowpalWabbit 命令行参数: https://github.com/VowpalWabbit/vowpal_wabbit/wiki/Command-line-arguments

多模态预测模型

class autogluon.tabular.models.MultiModalPredictorModel(**kwargs)[source]

文本预测模型

class autogluon.tabular.models.TextPredictorModel(**kwargs)[source]

不使用图像特征的多模态预测器

ImagePredictorModel

class autogluon.tabular.models.ImagePredictorModel(**kwargs)[source]

仅使用图像特征的MultimodalPredictor。 目前仅支持1个图像列,每个样本1张图像。 此外,还具有特殊的空图像处理功能,以提高在存在空图像(即图像路径为'')时的性能。

注意:尚未与MultimodalPredictor的内置空值处理进行比较。

集成模型

BaggedEnsembleModel

袋装集成元模型,它在训练数据的不同分割上多次拟合给定的模型。

StackerEnsembleModel

堆叠集成元模型,其功能与BaggedEnsembleModel完全相同,并具有利用基础模型的额外能力。

WeightedEnsembleModel

实现集成选择的加权集成元模型:https://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf

BaggedEnsembleModel

class autogluon.core.models.BaggedEnsembleModel(model_base: AbstractModel | Type[AbstractModel], model_base_kwargs: Dict[str, any] = None, random_state: int = 0, **kwargs)[source]

Bagged ensemble 元模型,它在训练数据的不同分割上多次拟合给定的模型。

对于某些子模型,如KNN,这可能只训练一个单一模型,并依赖子模型生成折叠外预测。

Parameters:
  • model_base (Union[AbstractModel, Type[AbstractModel]]) – 在bagging过程中重复拟合的基础模型。 如果是一个AbstractModel类,那么还需要提供model_base_kwargs,它将用于通过model_base(**model_base_kwargs)初始化模型。

  • model_base_kwargs (Dict[str, any], default = None) – 如果model_base是一个类,则用于初始化model_base的kwargs。

  • random_state (int, default = 0) – 用于在拟合期间将数据分割成交叉验证折叠的随机状态。

  • **kwargs – 请参阅AbstractModel文档

StackerEnsembleModel

class autogluon.core.models.StackerEnsembleModel(base_model_names: List[str] | None = None, base_models_dict: Dict[str, AbstractModel] | None = None, base_model_paths_dict: Dict[str, str] = None, base_model_types_dict: dict | None = None, base_model_types_inner_dict: dict | None = None, base_model_performances_dict: Dict[str, float] | None = None, **kwargs)[source]

Stack ensemble meta-model which functions identically to BaggedEnsembleModel with the additional capability to leverage base models.

通过在初始化时指定基础模型,堆叠模型可以在训练和推理过程中使用基础模型的预测作为特征。

与不堆叠的替代方案相比,此属性在许多情况下显著提高了模型质量。

堆叠模型可以作为其他堆叠模型的基础模型,从而实现多层堆叠集成。

Stacker kwargs 可以在 “ag_args_ensemble” 字典中指定。例如: ` predictor = TabularPredictor(...).fit(..., hyperparameters={"GBM": [{"ag_args_ensemble": {"max_base_models_per_type": 0}}]}) `

Parameters:

**kwargs

use_orig_features[True, False, “never”], 默认 True

如果为 True,将使用原始数据特征。 如果为 False,将丢弃原始数据特征,仅使用堆叠特征,除非没有堆叠特征存在(例如在第1层)。 如果为 “never”,将始终丢弃原始数据特征。如果没有堆叠特征存在(跳过第1层),将引发 NoStackFeatures 异常。

valid_stackerbool, 默认 True

如果为 True,将被标记为有效的堆叠模型。 如果为 False,将仅作为基础模型(第1层)进行拟合,而不会在堆叠层(第2层及以上)中进行拟合。

max_base_modelsint, 默认 0

作为该堆叠模型输入特征的基础模型的最大数量。 如果有超过 max_base_models 个基础模型可用,则仅使用验证分数最高的前 max_base_models 个模型。 如果为 0,则跳过此逻辑。

max_base_models_per_typeint | str, 默认 “auto”

类似于 max_base_models。如果有超过 max_base_models_per_type 个特定类型的模型可用, 则仅使用该类型的前 max_base_models_per_type 个模型。此操作在 max_base_models 过滤器之前进行。 如果为 “auto”,该值将根据训练样本的数量自适应设置。

更多的样本将导致更大的值,从 <1000 个样本时的 1 开始,增加到 >=50000 个样本时的 12。

如果为 0,则跳过此逻辑。

有关其他 kwargs,请参阅 BaggedEnsembleModel 文档

WeightedEnsembleModel

class autogluon.core.models.WeightedEnsembleModel(**kwargs)[source]

Weighted ensemble meta-model that implements Ensemble Selection: https://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf

必须将autogluon.core.models.GreedyWeightedEnsembleModel指定为model_base才能正常运行。

实验模型

FTTransformerModel

TabPFNModel

AutoGluon 模型包装器到 TabPFN 模型:https://github.com/automl/TabPFN

FastTextModel

FTTransformerModel

class autogluon.tabular.models.FTTransformerModel(**kwargs)[source]

TabPFNModel

class autogluon.tabular.models.TabPFNModel(**kwargs)[source]

AutoGluon 模型包装器到 TabPFN 模型:https://github.com/automl/TabPFN

论文: “TabPFN: 一种在一秒内解决小型表格分类问题的Transformer” 作者: Noah Hollmann, Samuel Müller, Katharina Eggensperger, 和 Frank Hutter

当推理速度不是问题时,TabPFN 是一个可行的模型选择,且训练数据的行数少于 10,000。

此外,TabPFN仅适用于最多10个类别和100个特征的分类任务。

要使用此模型,必须安装tabpfn。 要安装TabPFN,您可以运行pip install autogluon.tabular[tabpfn]pip install tabpfn

FastText模型

class autogluon.tabular.models.FastTextModel(**kwargs)[source]