autogluon.tabular.models¶
注意
此文档适用于高级用户,内容不够全面。
对于稳定的公共 API,请参考 TabularPredictor。
模型键¶
要使用 TabularPredictor 拟合模型,必须在 TabularPredictor.fit 的 hyperparameters 参数中指定它。
hyperparameters 接收一个模型字典,其中每个键是模型名称,值是模型超参数字典的列表。
例如
以下是键到模型的映射
以下是模型类型在训练时默认名称的映射
模型名称后缀¶
由 TabularPredictor 训练的模型其名称可以带有特殊含义的后缀。
后缀如下
“_Lx”:表示模型训练所在的堆栈级别 (x),例如 “_L1”, “_L2” 等。带有 “_L1” 后缀的模型是基础模型,意味着它不依赖于任何其他模型。如果模型没有此后缀,则它是基础模型,级别为 1 (“_L1”)。
“/Tx”:表示模型是通过超参数搜索 (HPO) 训练的。Tx 是 HPO 试验 #x 的缩写。例如 “LightGBM/T8”。
“_BAG”:表示模型是 Bagged 集成。Bagged 集成包含使用不同数据子集训练的模型(子模型)的多个实例。在推理期间,这些子模型分别对数据进行预测,并在最终结果中对其预测取平均值。这通常比任何单个模型单独使用都能获得更强的结果,但会显著降低推理速度。有关如何提高推理速度的说明,请参考 “_FULL”。
“_FULL”:表示模型已通过 TabularPredictor 的 refit_full 方法重新拟合。该模型没有验证分数,因为所有数据(训练和验证)都用作训练数据。通常,会有一个名称与此模型相同但减去 “_FULL” 后缀的另一个模型。该模型由于在训练期间使用了更多数据,通常可以优于原始模型,但如果原始模型是 Bagged 集成 (“_BAG”),则通常会较弱,但推理速度会快得多。
“_DSTL”:表示该模型是通过调用 TabularPredictor 的 distill 方法进行模型蒸馏创建的。蒸馏模型的验证分数只能与其他蒸馏模型进行比较。
“_x”:表示没有此后缀的名称已在其他模型中存在,因此添加此后缀以避免覆盖现有模型。例如 “LightGBM_2”。
模型¶
所有 AutoGluon 模型继承的抽象模型实现。 |
|
LightGBM 模型:https://lightgbm.readthedocs.io/en/latest/ |
|
CatBoost 模型:https://catboost.ai/ |
|
XGBoost 模型:https://xgboost.readthedocs.io/en/latest/ |
|
Random Forest 模型 (scikit-learn):https://scikit-learn.cn/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html |
|
Extra Trees 模型 (scikit-learn):https://scikit-learn.cn/stable/modules/generated/sklearn.ensemble.ExtraTreesClassifier.html#sklearn.ensemble.ExtraTreesClassifier |
|
KNearestNeighbors 模型 (scikit-learn):https://scikit-learn.cn/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html |
|
线性模型 (scikit-learn):https://scikit-learn.cn/stable/modules/generated/sklearn.linear_model.LogisticRegression.html |
|
用于表格数据分类/回归的 PyTorch 神经网络模型。 |
|
用于处理表格数据的 fastai v1 神经网络模型类。 |
|
不使用图像特征的 MultimodalPredictor |
|
仅使用图像特征的 MultimodalPredictor。目前仅支持 1 个图像列,每个样本 1 个图像。此外,还具有特殊的空图像处理功能,可在存在空图像(即图像路径为 '')时提高性能。注意:尚未将空处理与 MultimodalPredictor 的内置空处理进行比较。 |
AbstractModel¶
- class autogluon.tabular.models.AbstractModel(path: str | None = None, name: str | None = None, problem_type: str | None = None, eval_metric: str | Scorer | None = None, hyperparameters: dict | None = None)[source]¶
所有 AutoGluon 模型继承的抽象模型实现。
- 参数:
path (str, default = None) – 存储所有输出的目录位置。如果为 None,则选择一个新的唯一时间戳目录。
name (str, default = None) – path 中模型将要保存的子目录名称。最终的模型目录将是 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, default = 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.cn/stable/modules/classes.html#sklearn-metrics-metrics
只要您自己的评估函数遵循文件夹 autogluon.core.metrics 中定义的函数的格式,您也可以在此处传入。
hyperparameters – 模型将使用的超参数(可以是搜索空间而非固定值)。如果为 None,则使用模型默认值。这与传入空字典相同。
- can_compile(compiler_configs: dict = None) bool [source]¶
验证模型是否可以使用编译器配置进行编译。
- 参数:
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。
- compile(compiler_configs: dict = None)[source]¶
编译训练好的模型以加快推理速度。
注意: - 模型在编译前应已拟合。 - 如果编译器的 save_in_pkl 属性为 False,则 self.model 将设置为 None。
- 参数:
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]¶
通过置换洗牌计算特征重要性。
- 参数:
X
y
features
silent
importance_as_list
kwargs
- 返回类型:
特征重要性的 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]¶
估算模型在训练期间的峰值内存使用量。
- 参数:
X (pd.DataFrame) – 训练数据特征
- 返回:
int
- 返回类型:
训练期间估算的峰值内存使用量(字节)
- estimate_memory_usage_child(X: DataFrame, **kwargs) int [source]¶
估算子模型在训练期间的峰值内存使用量。
如果模型不是 Bagged 模型(即没有子模型),则返回其自身的内存使用量估算值。
- 参数:
X (pd.DataFrame) – 训练数据特征
**kwargs
- 返回:
int
- 返回类型:
子模型在训练期间估算的峰值内存使用量(字节)
- 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]¶
在无需初始化模型的情况下,估算模型训练期间的峰值内存使用量。
- 参数:
X (pd.DataFrame) – 训练数据特征
y (pd.Series, optional) – 训练数据真实标签。如果 problem_type 或 num_classes 未指定,则必须指定此参数。
hyperparameters (dict, optional) – 模型超参数
problem_type (str, default = "infer") – problem_type。如果为 “infer”,则将根据 y 进行推断。
num_classes – num_classes。如果为 “infer”,则将根据 y 进行推断。
**kwargs – 其他可能影响模型内存使用的可选关键字拟合参数。
- 返回:
int
- 返回类型:
训练期间估算的峰值内存使用量(字节)
- 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 方法。
- 参数:
X (pd.DataFrame) – 训练数据特征
y (pd.Series, optional) – 训练数据真实标签。如果 problem_type 或 num_classes 未指定,则必须指定此参数。
hyperparameters (dict, optional) – 模型超参数
problem_type (str, default = "infer") – problem_type。如果为 “infer”,则将根据 y 进行推断。
num_classes – num_classes。如果为 “infer”,则将根据 y 进行推断。
**kwargs – 其他可能影响模型内存使用的可选关键字拟合参数。
- 返回:
int
- 返回类型:
子模型在训练期间估算的峰值内存使用量(字节)
- fit(**kwargs)[source]¶
拟合模型以根据 X 预测 y 中的值。
模型不应覆盖 fit 方法,而应覆盖具有相同参数的 _fit 方法。
- 参数:
X (DataFrame) – 训练数据特征。
y (Series) – 训练数据真实标签。
X_val (DataFrame, default = None) – 验证数据特征。如果为 None,则通过验证分数进行的早期停止将被禁用。
y_val (Series, default = None) – 验证数据真实标签。如果为 None,则通过验证分数进行的早期停止将被禁用。
X_test (DataFrame, default = 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
, default = None) – 包含可用于识别特殊特征(如文本 ngrams 和 datetime)以及哪些特征是数值型或类别型的特征类型信息。如果为 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 数量
- classmethod get_ag_priority(problem_type: str | None = None) int [source]¶
返回由 cls.ag_priority 和 cls.ag_priority_by_problem_type 定义的 AutoGluon 拟合优先级。
- get_memory_size(allow_exception: bool = False) int | None [source]¶
序列化模型对象 (self) 并返回以字节为单位的大小。如果 self 无法序列化,将引发异常。
注意:这将暂时使模型的内存使用量增加一倍,因为原始模型和序列化版本都将存在于内存中。如果模型大于剩余可用内存,这可能导致内存不足错误。
- 参数:
allow_exception (bool, default = False) – 如果为 True,并且在计算内存大小时发生异常,则返回 None 而不是引发异常。例如,如果模型在拟合期间失败并处于混乱的内部状态,然后调用了 get_memory_size,它可能仍然包含不可序列化的对象。通过设置 allow_exception=True,我们可以避免在这种情况下崩溃。例如:“AttributeError: Can’t pickle local object ‘func_generator.<locals>.custom_metric’”
- 返回:
memory_size – 序列化模型对象以字节为单位的内存大小。如果发生异常且 allow_exception=True,则为 None。
- 返回类型:
int | None
- get_minimum_resources(is_gpu_available: bool = False) Dict[str, int | float] [source]¶
- 参数:
is_gpu_available (bool, default = False) – 系统中 GPU 是否可用。可以在 CPU 和 GPU 上训练的模型可以根据此决定所需的最低资源。
返回一个字典,其中包含拟合模型所需的最低资源要求。
如果子类需要更多资源进行
如果某个资源不是输出
非必需的。
有效键
- get_params_aux_info() dict [source]¶
将学习曲线评分器对象转换为其名称字符串。
返回:
params_aux 字典,其中 curve_metrics 字段已更改(如果适用)。
- get_trained_params() dict [source]¶
返回训练后模型的超参数。如果模型发生了早停,则此参数将包含模型在推理时使用的 epoch/迭代次数,而不是在拟合时指定的 epoch/迭代次数。这用于生成模型模板,以便在所有数据(无验证集)上重新拟合。
- hyperparameter_tune(hyperparameter_tune_kwargs='auto', hpo_executor: HpoExecutor = None, time_limit: float = None, **kwargs)[source]¶
执行模型的超参数调优,根据在初始化期间 hyperparameters 中提供的搜索空间拟合模型的多个变体。
- 参数:
超参数调优策略和 kwargs(例如,要运行多少次 HPO 试验)。有效键
Hyperparameter tuning strategy and kwargs (for example, how many HPO trials to run). Valid keys
’num_trials’:您想要执行的 hpo 试验次数。'scheduler':hpo 实验使用的调度器。
- 有效值
’local’:本地 FIFO 调度器。如果使用 Custom 后端,则为顺序执行;如果使用 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 期间只会使用部分时间限制,因为它稍后需要剩余时间来拟合所有试验的折叠。
与您传递给 fit 调用的 kwargs 相同,例如
- Same kwargs you would pass to fit call, such as
X y X_val y_val feature_metadata sample_weight sample_weight_val
- 返回:
Tuple of (hpo_results (Dict[str, dict], hpo_info: Any))
一个将试验模型名称映射到包含以下内容的字典:
- A dictionary of trial model names to a dictionary containing
- path: str
训练后模型工件的绝对路径。用于加载模型。
- val_score: float
模型的 val_score
- trial: int
模型的试验编号,从 0 开始。
- hyperparameters: dict
模型试验的超参数配置。
hpo_info (Any) – 包含调度器特定逻辑的高级输出,主要用于调试。对于 Ray Tune 后端,这将是一个 Analysis 对象:https://docs.rayai.org.cn/en/latest/tune/api/doc/ray.tune.ExperimentAnalysis.html
- is_initialized() bool [source]¶
如果模型已初始化,则返回 True。这表示模型是否已推断出各种信息,例如 problem_type 和 num_classes。当调用 .fit 或 .hyperparameter_tune 时,模型会自动初始化。
- is_valid() bool [source]¶
如果模型能够在新数据上进行推理(如果是普通模型)或已生成折叠外预测(如果是 bagged 模型),则返回 True。这表明模型是否可以用作拟合堆叠集成模型的基础模型。
- classmethod load(path: str, reset_paths: bool = True, verbose: bool = True)[source]¶
将模型从磁盘加载到内存。
- 参数:
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, default True) – 是否记录加载文件的位置。
- 返回:
model – 加载的模型对象。
- 返回类型:
cls
- classmethod load_learning_curves(path: str) List [source]¶
将 learning_curve 数据从磁盘加载到内存。
- 参数:
path (str) – 保存的模型路径,不包含文件名。这通常应该是一个以“/”字符(或取决于操作系统的适当路径分隔符值)结尾的目录路径。模型文件通常位于 os.path.join(path, cls.model_file_name) 中。
- 返回:
learning_curves – 加载的学习曲线数据。
- 返回类型:
List
- predict(X, **kwargs) ndarray [source]¶
返回 X 的类预测。对于二分类和多分类问题,这以 1d numpy 数组的形式返回预测的类标签。对于回归问题,这以 1d numpy 数组的形式返回预测值。
- predict_from_proba(y_pred_proba: ndarray) ndarray [source]¶
将预测概率转换为预测。
- 参数:
y_pred_proba (np.ndarray) – 要转换为预测的预测概率。
- 返回:
y_pred – 从 y_pred_proba 获得的预测。
- 返回类型:
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_time 或 self.predict_n_size 为 None,则返回 None。
- predict_proba(X, *, normalize: bool | None = None, record_time: bool = False, **kwargs) ndarray [source]¶
返回 X 的类预测概率。对于二分类问题,这以 1d numpy 数组的形式返回正类标签概率。对于多分类问题,这以 2d numpy 数组的形式返回每个类的类标签概率。对于回归问题,这以 1d numpy 数组的形式返回预测值。
- 参数:
X – 用于预测的数据。
normalize (bool | None, default = None) – 返回之前是否对预测进行归一化。如果为 None,则默认为 self.normalize_pred_probas。
record_time (bool, default = False) – 如果为 True,则将在 self.predict_time 中记录预测所花费的时间,并在 self.predict_n_size 中记录 X 的行数。
kwargs – 传递给 self._predict_proba 的关键字参数。
- 返回:
y_pred_proba – 预测概率
- 返回类型:
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 所需的信息。
- 参数:
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 对象一部分的变量,如果模型之前已持久化,则需要覆盖磁盘上的模型。
模型不必实现此方法。
- save(path: str | None = None, verbose: bool = True) str [source]¶
将模型保存到磁盘。
- 参数:
path (str, default None) – 保存的模型路径,不包含文件名。这通常应该是一个以“/”字符(或取决于操作系统的适当路径分隔符值)结尾的目录路径。如果为 None,则使用 self.path。最终的模型文件通常保存到 os.path.join(path, self.model_file_name) 中。
verbose (bool, default True) – 是否记录保存文件的位置。
- 返回:
path – 保存的模型路径,不包含文件名。使用此值通过 cls.load(path) 从磁盘加载模型,其中 cls 是模型对象的类,例如 model = RFModel.load(path)。
- 返回类型:
str
- save_learning_curves(metrics: str | ~typing.List[str], curves: dict[dict[slice(<class 'str'>, typing.List[float], None)]], path: str = None) str [source]¶
将学习曲线保存到磁盘。
- 输出曲线格式
- out = [
指标, [
- [ # log_loss
[0.693147, 0.690162, …], # 训练 [0.693147, 0.690162, …], # 验证 [0.693147, 0.690162, …], # 测试
], [ # accuracy
[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, …], # 测试
],
]
]
- 参数:
metrics (str or list(str)) – 曲线每次迭代计算的所有评估指标列表
评估集及其学习曲线字典的字典。每个学习曲线字典包含在每次迭代计算的评估指标。例如
Dictionary of evaluation sets and their learning curve dictionaries. Each learning curve dictionary contains evaluation metrics computed at each iteration. e.g.
- 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)。
- 返回:
path – 保存的曲线路径,不包含文件名。
- 返回类型:
str
LGBModel¶
- class autogluon.tabular.models.LGBModel(**kwargs)[source]¶
LightGBM 模型:https://lightgbm.readthedocs.io/en/latest/
超参数选项:https://lightgbm.readthedocs.io/en/latest/Parameters.html
- 额外超参数选项
ag.early_stop : int, 指定早停轮数。默认为自适应策略。建议保持默认。
CatBoostModel¶
- class autogluon.tabular.models.CatBoostModel(**kwargs)[source]¶
CatBoost 模型:https://catboost.ai/
超参数选项:https://catboost.ai/en/docs/references/training-parameters
XGBoostModel¶
- class autogluon.tabular.models.XGBoostModel(**kwargs)[source]¶
XGBoost 模型:https://xgboost.readthedocs.io/en/latest/
超参数选项:https://xgboost.readthedocs.io/en/latest/parameter.html
RFModel¶
- class autogluon.tabular.models.RFModel(**kwargs)[source]¶
Random Forest 模型 (scikit-learn):https://scikit-learn.cn/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html
XTModel¶
- class autogluon.tabular.models.XTModel(**kwargs)[source]¶
Extra Trees 模型 (scikit-learn):https://scikit-learn.cn/stable/modules/generated/sklearn.ensemble.ExtraTreesClassifier.html#sklearn.ensemble.ExtraTreesClassifier
KNNModel¶
- class autogluon.tabular.models.KNNModel(**kwargs)[source]¶
KNearestNeighbors 模型 (scikit-learn):https://scikit-learn.cn/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html
LinearModel¶
- class autogluon.tabular.models.LinearModel(**kwargs)[source]¶
线性模型 (scikit-learn):https://scikit-learn.cn/stable/modules/generated/sklearn.linear_model.LogisticRegression.html
模型后端因 problem_type 而异
TabularNeuralNetTorchModel¶
NNFastAiTabularModel¶
- class autogluon.tabular.models.NNFastAiTabularModel(**kwargs)[source]¶
用于处理表格数据的 fastai v1 神经网络模型类。
- 超参数
‘y_scaler’:在回归问题中,模型可能在新数据上给出不合理的预测。为了解决这个问题,AutoGluon 默认对回归问题的 y 值进行缩放。此属性允许为 y 值传递自定义缩放器。请注意,中间迭代指标会受到此变换的影响,因此中间迭代得分将与最终得分不同(最终得分将是正确的)。https://scikit-learn.cn/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.fastai.net.cn/callback.schedule.html#Learner.fit_one_cycle,一周期策略论文:https://arxiv.org/abs/1803.09820
‘epochs’:轮数;默认值为 30
# 早停设置。详情请参阅此处:https://docs.fastai.net.cn/callback.tracker.html#EarlyStoppingCallback ‘early.stopping.min_delta’:0.0001,‘early.stopping.patience’:10,
MultiModalPredictorModel¶
TextPredictorModel¶
ImagePredictorModel¶
集成模型¶
Bagged 集成元模型,它在训练数据的不同分割上多次拟合给定模型。 |
|
堆叠集成元模型,其功能与 |
|
加权集成元模型,实现了集成选择 (Ensemble Selection):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 集成元模型,它在训练数据的不同分割上多次拟合给定模型。
对于某些子模型(例如 KNN),这可能只训练一个模型,而是依赖于子模型生成折叠外预测。
- 参数:
model_base (Union[AbstractModel, Type[AbstractModel]]) – 在装袋过程中重复拟合的基础模型。如果是一个 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]¶
堆叠集成元模型,其功能与
BaggedEnsembleModel
相同,但增加了利用基础模型的能力。通过在初始化期间指定基础模型,堆叠器模型可以在训练和推理期间使用基础模型的预测作为特征。
与非堆叠方法相比,此属性在许多情况下可以显著提高模型质量。
堆叠器模型可以作为其他堆叠器模型的基础模型,从而实现多层堆叠集成。
Stacker 的 kwargs 可以在 “ag_args_ensemble” 字典中指定。例如:
` predictor = TabularPredictor(...).fit(..., hyperparameters={"GBM": [{"ag_args_ensemble": {"max_base_models_per_type": 0}}]}) `
- 参数:
与您传递给 fit 调用的 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]¶
加权集成元模型,实现了集成选择 (Ensemble Selection):https://www.cs.cornell.edu/~alexn/papers/shotgun.icml04.revised.rev2.pdf
必须将
autogluon.core.models.GreedyWeightedEnsembleModel
指定为 model_base 才能正常工作。
实验性模型¶
TabPFN 模型 的 AutoGluon 模型包装器:https://github.com/automl/TabPFN |
|
FTTransformerModel¶
TabPFNModel¶
- class autogluon.tabular.models.TabPFNModel(**kwargs)[source]¶
TabPFN 模型 的 AutoGluon 模型包装器:https://github.com/automl/TabPFN
论文:“TabPFN: A Transformer That Solves Small Tabular Classification Problems in a Second” 作者:Noah Hollmann, Samuel Müller, Katharina Eggensperger, and Frank Hutter
TabPFN 是一个可行的模型选项,当推理速度不是问题,并且训练数据行数少于 10,000 时。
此外,TabPFN 仅适用于最多包含 10 个类别和 100 个特征的分类任务。
要使用此模型,必须安装 tabpfn。要安装 TabPFN,可以运行 pip install autogluon.tabular[tabpfn] 或 pip install tabpfn。