import boto3
import sagemaker
from sagemaker.estimator import Estimator
from sagemaker.inputs import TrainingInput
# Set up SageMaker session
sagemaker_session = sagemaker.Session()
role = sagemaker.get_execution_role()
# Define estimator
estimator = Estimator(
image_uri="your-docker-image-uri",
role=role,
instance_count=1,
instance_type="ml.m5.xlarge",
output_path="s3://your-bucket/output"
)
# Set hyperparameters
estimator.set_hyperparameters(epochs=10, learning_rate=0.1)
# Prepare data
train_data = TrainingInput(
s3_data="s3://your-bucket/train",
content_type="text/csv"
)
# Train the model
estimator.fit({"train": train_data})
# Deploy the model
predictor = estimator.deploy(
initial_instance_count=1,
instance_type="ml.t2.medium"
)
# Make predictions
result = predictor.predict("sample input data")
print(result)