machine-learning - 在 sagemaker 中使用相同的预处理代码进行训练和推理

标签 machine-learning amazon-sagemaker amazon-machine-learning

我正在致力于为时间序列数据构建机器学习管道,其目标是经常重新训练和更新模型以进行预测。

  • 我编写了一个预处理代码来处理时间序列变量并对其进行转换。

我对如何使用相同的预处理代码进行训练和推理感到困惑?我应该编写一个 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])

有关更多详细信息,请参阅以下链接。

https://github.com/awslabs/amazon-sagemaker-examples/blob/master/sagemaker-python-sdk/scikit_learn_inference_pipeline/Inference%20Pipeline%20with%20Scikit-learn%20and%20Linear%20Learner.ipynb

关于machine-learning - 在 sagemaker 中使用相同的预处理代码进行训练和推理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58926337/

相关文章:

python-3.x - 关于 lambda 函数的 Sagemaker SDK

amazon-web-services - AWS 机器学习重新训练模型

amazon-web-services - 如何在 Amazon Machine Learning 上构建推荐系统

machine-learning - 哪种预训练模型最适合灾难分类

machine-learning - CountVectorizer MultinomialNB ValueError : dimension mismatch

performance - 频繁项集最佳算法和库

amazon-web-services - AWS 机器学习数据

python - 使用决策树比较 scikit 学习聚类

python - Sagemaker 预测本地实例,JSON 错误

amazon-web-services - AWS Sagemaker 与 ECS 模型托管对比