超参数优化和 AutoMLHyperparameter tuning and AutoML

AutoML(自动化机器学习)是指自动完成开发机器学习模型的过程。AutoML (automated machine learning) refers to automating the process of developing machine learning models. Databricks Runtime 机器学习整合了 MLflow 和 Hyperopt,这两款开源工具可自动完成模型选择和超参数优化过程。Databricks Runtime for Machine Learning incorporates MLflow and Hyperopt, two open source tools that automate the process of model selection and hyperparameter tuning.

自动化 MLflow 跟踪Automated MLflow tracking

MLflow 是用于管理端到端机器学习生命周期的开源平台。MLflow is an open source platform for managing the end-to-end machine learning lifecycle. 对于 AutoML,MLflow 通过 Apache Spark MLlib 为模型优化提供自动跟踪。For AutoML, MLflow provides automated tracking for model tuning with Apache Spark MLlib. 借助自动化 MLflow 跟踪时,可在使用 CrossValidatorTrainValidationSplit 运行优化代码时自动记录指定的超参数和评估指标,从而简化识别最佳模型的过程。With automated MLflow tracking, when you run tuning code using CrossValidator or TrainValidationSplit, the specified hyperparameters and evaluation metrics are automatically logged, making it easy to identify the optimal model. 自动化 MLflow 跟踪仅可用于 Python 笔记本。Automated MLflow tracking is available for Python notebooks only.

使用 Hyperopt 进行超参数优化 Hyperparameter tuning with Hyperopt

Hyperopt 是一个开源库,可简化分布式超参数优化。Hyperopt is an open-source library that facilitates distributed hyperparameter tuning. 你还可使用条件参数跨不同的模型体系结构自动搜索。You can also automatically search across different model architectures using conditional parameters.

Hyperopt 可基于标量值目标函数的一组输入参数优化该函数。Hyperopt optimizes a scalar-valued objective function over a set of input parameters to that function. 使用 Hyperopt 对机器学习模型进行超参数优化时,需将目标函数定义为使用超参数作为输入,并输出训练或验证损失。When using Hyperopt to do hyperparameter tuning for your machine learning models, you define the objective function to take hyperparameters of interest as input and output a training or validation loss. 在目标函数中加载训练数据,使用从输入中收到的超参数训练机器学习模型,并像平时一样每隔几次迭代保存模型检查点。In the objective function, you load the training data, train your machine learning model with hyperparameters received from the input and save model checkpoints every several iterations as usual. Hyperopt 提供两种优化算法 - 随机搜索和贝叶斯方法 Tree of Parzen Estimator (TPE);与网格搜索等暴力算法相比,这两种算法的计算效率更高。Hyperopt offers two tuning algorithms—Random Search and the Bayesian method Tree of Parzen Estimators (TPE)—which offer improved compute efficiency compared to a brute force approach such as grid search.

可通过两种方式在分布式设置中使用 Hyperopt:There are two ways to use Hyperopt in a distributed setting:

  • 将分布式 Hyperopt 与单计算机训练算法配合使用。Use distributed Hyperopt with single-machine training algorithms. 具体而言,在调用 hyperopt.fmin() 时使用 SparkTrials 类,并在目标函数中运行单计算机训练算法。Specifically, you use the SparkTrials class when calling hyperopt.fmin() and run single-machine training algorithms in the objective function.
  • 将单计算机 Hyperopt 与分布式训练算法配合使用。Use single-machine Hyperopt with distributed training algorithms. 具体而言,在调用 hyperopt.fmin() 时使用默认的 base.Trials 类,并在目标函数中运行分布式训练算法。Specifically, you use the default base.Trials class when calling hyperopt.fmin() and run distributed training algorithms in the objective function.

有关这两种用例的详细演示,请参阅以下文章:See the following articles for detailed demonstrations of these two use cases:

端到端示例笔记本使用 Hyperopt 和 SparkTrials 来运行并行超参数扫描,从而并行训练多个模型。This end-to-end example notebook uses Hyperopt and SparkTrials to run a parallel hyperparameter sweep to train multiple models in parallel. 此示例还使用 MLflow 跟踪每个参数配置的性能。This example also tracks the performance of each parameter configuration using MLflow.