How to fix Sagemaker's "No finished training job found associated with this estimator" error?

I ran a complete AWS SageMaker Autopilot experiment. I now want to generate batch forecasts using this model but I get the error: No finished training job found associated with this estimator. Please make sure this estimator is only used for building workflow config.

I'm using this tutorial as reference.

Here's my SageMaker Studio notebook Python code.

import sagemaker 
from sagemaker import get_execution_role
import boto3 
import os
from time import gmtime, strftime, sleep

session = sagemaker.Session()
bucket = sagemaker.Session().default_bucket()
prefix = trial-01
region = sagemaker.Session().boto_region_name
role = sagemaker.get_execution_role()

# The location of the test dataset
batch_input = 's3://{}/{}/test'.format(bucket, prefix)

# The location to store the results of the batch transform job
batch_output = 's3://{}/{}/batch-prediction'.format(bucket, prefix)

container=sagemaker.image_uris.retrieve(xgboost, region, 1.2-1)

test_model=sagemaker.estimator.Estimator(
    image_uri=container,
    role=role,
    instance_count=1,
    instance_type='ml.m4.xlarge',
    volume_size=5,
    output_path=batch_output,
    sagemaker_session=sagemaker.Session()
)

transformer = test_model.transformer(
    instance_count=1, 
    instance_type='ml.m4.xlarge', 
    output_path=batch_output
)

Topic sagemaker supervised-learning aws python machine-learning

Category Data Science


I think that you have to train your model first. To do that in sagemaker, you can do the following. I assume that you want to train a machine learning model without using a python script as an entry point.

First, define your hyper-parameters :

test_model.set_hyperparameters(
    max_depth = 5,
    eta = 0.2,
    gamma = 4,
    min_child_weight = 6,
    subsample = 0.7,
    objective = "binary:logistic",
    num_round = 1000
)

Then you have to define your train and validation inputs. for example :

train_input = TrainingInput(
    "s3://{}/{}/{}".format(bucket, prefix, "data/train.csv"), content_type="csv"
)
validation_input = TrainingInput(
    "s3://{}/{}/{}".format(bucket, prefix, "data/validation.csv"), content_type="csv"
)

Finally, you have to call the .fit() method to train your model :

test_model.fit({"train": train_input, "validation": validation_input}, wait=True)

In case that you want to train a model through a python script (an entry point), you can refer to this example : https://github.com/aws-samples/amazon-sagemaker-script-mode/tree/master/tf-sentiment-script-mode

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.