如何使用自定义模型评估算法调整超参数?
How to tune hyperparameters using custom model evaluation algorithm?
在我的模型评估算法中,我想获得验证数据的模型预测,并应用一种算法,该算法根据验证数据和预测对一些真实场景进行建模和模仿。
在我的场景中,评估算法不仅取决于真实目标值 (y_true) 和预测 (y_pred),还取决于输入验证数据 (X) 以输出最终模型分数。因此,我似乎无法为我的用例使用带有自定义指标的估算器。
实现evaluation/scoring算法对我来说是微不足道的,但是我如何将评估算法的输出传递回ML引擎的超参数调整任务,以便它可以实际优化超参数并输出最佳超参数值超参数调整任务结束?
实现 evaluation/scoring 算法后,使用 hypertune 包写出数字:
import hypertune
hpt = hypertune.HyperTune()
# every time you evaluate, write out the evaluation metric
eval_output_value = your_evaluation_algo(...)
hpt.report_hyperparameter_tuning_metric(
hyperparameter_metric_tag='mymetric',
metric_value=eval_output_value,
global_step=0)
然后,将上面的metric_tag指定为CMLE的评估指标。
您可以使用 PyPI 安装 hypertune:
pip install cloudml-hypertune
在训练包的 setup.py 中,确保指定 hypertune 包:
install_requires=[
..., # other dependencies
'cloudml-hypertune', # Required for hyperparameter tuning.
],
有关使用 scikit-learn 的示例,请参阅 https://github.com/GoogleCloudPlatform/training-data-analyst/tree/master/blogs/sklearn/babyweight,因此不能依赖 TensorFlow 的 Estimator API 来写出评估指标。
在我的模型评估算法中,我想获得验证数据的模型预测,并应用一种算法,该算法根据验证数据和预测对一些真实场景进行建模和模仿。
在我的场景中,评估算法不仅取决于真实目标值 (y_true) 和预测 (y_pred),还取决于输入验证数据 (X) 以输出最终模型分数。因此,我似乎无法为我的用例使用带有自定义指标的估算器。
实现evaluation/scoring算法对我来说是微不足道的,但是我如何将评估算法的输出传递回ML引擎的超参数调整任务,以便它可以实际优化超参数并输出最佳超参数值超参数调整任务结束?
实现 evaluation/scoring 算法后,使用 hypertune 包写出数字:
import hypertune
hpt = hypertune.HyperTune()
# every time you evaluate, write out the evaluation metric
eval_output_value = your_evaluation_algo(...)
hpt.report_hyperparameter_tuning_metric(
hyperparameter_metric_tag='mymetric',
metric_value=eval_output_value,
global_step=0)
然后,将上面的metric_tag指定为CMLE的评估指标。
您可以使用 PyPI 安装 hypertune:
pip install cloudml-hypertune
在训练包的 setup.py 中,确保指定 hypertune 包:
install_requires=[
..., # other dependencies
'cloudml-hypertune', # Required for hyperparameter tuning.
],
有关使用 scikit-learn 的示例,请参阅 https://github.com/GoogleCloudPlatform/training-data-analyst/tree/master/blogs/sklearn/babyweight,因此不能依赖 TensorFlow 的 Estimator API 来写出评估指标。