Lab build

Mobile price classifier on SageMaker

Trains a Random Forest mobile price classifier on SageMaker spot instances and serves it from an endpoint.

Role
Builder, end to end
Group
MLOps
Services
AI & LLM systems · MLOps & cloud

What it does

Mobile price data is split, uploaded to S3 and used by a custom scikit-learn training script run through the SageMaker SKLearn estimator on a spot ml.m5.large instance. The model artifact is wrapped as an SKLearnModel, deployed to a real-time ml.m4.xlarge endpoint, queried with test rows and then deleted.

What was built

  1. 01

    Session uploads train and test CSVs to an S3 prefix used as the training input.

  2. 02

    script.py parses hyperparameters with argparse, trains a RandomForestClassifier and saves model.joblib with a model_fn loader.

  3. 03

    SKLearn estimator runs the script on ml.m5.large with spot instances and a one-hour max run.

  4. 04

    SKLearnModel deploys to an ml.m4.xlarge endpoint; predictions are tested and the endpoint is deleted with boto3.

The pipeline, layer by layer

Four layers, one pipeline.

  1. L1Data

    • Mobile price CSV
    • S3 upload
  2. L2Training

    • SageMaker spot training job
    • Random Forest script
  3. L3Model

    • SKLearnModel artifact
  4. L4Serving

    • Real-time endpoint

Stack

  • Amazon SageMaker
  • SageMaker Python SDK
  • scikit-learn
  • Amazon S3
  • AWS IAM
  • boto3
  • pandas

Next lab build · 24 / 46

Keras CNN training and tuning on SageMaker

Trains a Keras MNIST CNN on SageMaker GPU instances, tunes hyperparameters and deploys the best model.

Previous: Iris classifier with CircleCI, GitLab CI and GitHub Actions

Need a system like this in production? Tell us about it.