Solution: Train and Evaluate ML Model

Let's take a look at the solution for this exercise.

We'll cover the following

Solution

Here are the steps required to reproduce this solution:

  1. Run the train.py script to train a model and generate the data files that you’ll upload to Amazon S3 in the next step.
  2. Create a bucket to store the train/ test data used for training the model. The Lambda function will be aware of this location. The value of the environment variable DATA_PATH is s3://BUCKET_NAME/. Replace the BUCKET_NAME with a bucket name of your choice.
  3. By default, a Lambda function has no permissions except for persisting its logs. For the Lambda function to list and read data from the previously created bucket, the default Lambda role permissions created automatically by Serverless have already been adjusted (see iam block in provider section). This gives the Lambda function additional minimal privileges for listing all buckets, and basic data operations on the created bucket.
  4. Substitute SERVERLESS_ORG, AWS_BUCKET_NAME and DATA_PATH, and then deploy your own service.
  5. Test the service in your Lambda’s test window by providing the following payload where partition is equal to test or train. How different is the score?
{
  "partition": "test"
}

Playground

Use the following widget to perform the abovementioned steps.

Get hands-on with 1400+ tech skills courses.