<jupyter_start><jupyter_text>Using the Custom Python Algorithm Container Image for Training & Inference with Amazon SageMaker Local Mode This notebook contains the code to help readers work through one of the recipes of the book [Machine Learning with Amazon SageMaker Cookbook: 80 proven recipes for data scientists and developers to perform ML experiments and deployments](https://www.amazon.com/Machine-Learning-Amazon-SageMaker-Cookbook/dp/1800567030)  How to do it...<jupyter_code>!pip install 'sagemaker[local]' --upgrade
s3_bucket = "<insert S3 bucket name here>"
prefix = "chapter01"
training_s3_input_location = f"s3://{s3_bucket}/{prefix}/input/training_data.csv"
training_s3_output_location = f"s3://{s3_bucket}/{prefix}/output/custom/"
import sagemaker
sagemaker.__version__
container="581320662326.dkr.ecr.us-east-1.amazonaws.com/chap02_python:1"
import sagemaker 
import boto3
from sagemaker import get_execution_role 

role = get_execution_role()
from sagemaker.local import LocalSession

session = LocalSession()
session.config = {'local': {'local_code': True}}
from sagemaker.inputs import TrainingInput

train = TrainingInput(training_s3_input_location, content_type="text/csv")
estimator = sagemaker.estimator.Estimator(
    container,
    role, 
    instance_count=1, 
    base_job_name="abcdefghij",
    instance_type='ml.m5.large',
    output_path=training_s3_output_location,
    sagemaker_session=sagemaker.Session())
estimator.set_hyperparameters(a=1, b=2, c=3)
estimator.fit({'train': train})
predictor = estimator.deploy(
    initial_instance_count=1, 
    instance_type='ml.t2.medium', 
    endpoint_name="custom-local-py-endpoint")
predictor.predict("1")
predictor.delete_endpoint()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10453762205628948, 'fraction_numerical': 0.028144744399770247, 'mean_word_length': 6.258333333333334, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '233325', 'license': 'MIT', 'n_tokens_mistral': 589, 'n_tokens_neox': 548, 'n_words': 123, 'path': 'Chapter02/07 - Using the Custom Python Algorithm Container Image for Training & Inference with Amazon SageMaker Local Mode.ipynb', 'repo_name': 'MARKOM/sagemaker-cookbook', 'size': '1741'}