我正在致力于为时间序列数据构建机器学习管道,其目标是经常重新训练和更新模型以进行预测。
- 我编写了一个预处理代码来处理时间序列变量并对其进行转换。
我对如何使用相同的预处理代码进行训练和推理感到困惑?我应该编写一个 lambda 函数来预处理我的数据还是有其他方法
调查来源:
aws sagemaker 团队给出的两个示例使用 AWS Glue 进行 ETL 转换。
inference_pipeline_sparkml_xgboost_abalone
inference_pipeline_sparkml_blazingtext_dbpedia
我是 aws sagemaker 的新手,正在尝试学习、理解和构建流程。如有任何帮助,我们将不胜感激!
最佳答案
以倒退的方式回答问题。
根据您的示例,下面的代码是将两个模型组合在一起的推理管道。在这里我们需要删除sparkml_model并获取我们的sklearn模型。
sm_model = PipelineModel(name=model_name, role=role, models=[sparkml_model, xgb_model])
在放置 sklearn 模型之前,我们需要 SageMaker 版本的 SKLearn 模型。
First create the SKLearn Estimator using SageMaker Python library.
sklearn_preprocessor = SKLearn(
entry_point=script_path,
role=role,
train_instance_type="ml.c4.xlarge",
sagemaker_session=sagemaker_session)
script_path - 这是包含所有预处理逻辑或转换逻辑的 python 代码。下面给出的链接中的“sklearn_abalone_featurizer.py”。
Train the SKLearn Estimator
sklearn_preprocessor.fit({'train': train_input})
Create the SageMaker model from the SKLearn Estimator that can put in inference pipeline.
sklearn_inference_model = sklearn_preprocessor.create_model()
Inference PipeLineModel creation will be modified as indicated below.
sm_model = PipelineModel(name=model_name, role=role, models=[sklearn_inference_model, xgb_model])
有关更多详细信息,请参阅以下链接。
关于machine-learning - 在 sagemaker 中使用相同的预处理代码进行训练和推理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58926337/