A. Nigam
A. Nigam

Reputation: 139

Is there a way to export or view a classifier created in sagemaker so that we can see what weights/constants are used in model evaluation

I created a simple linear learner model using sagemaker, and although I can deploy it on a test data set, I would like to be able to get the actual equation that the model uses to classify values (ie for linear regression the equation of the line).

Upvotes: 4

Views: 247

Answers (1)

Olivier Cruchant
Olivier Cruchant

Reputation: 4047

You can open the model artifact with mxnet and view the weights and the bias - see code below, pasted from this forum post

import os
import mxnet as mx
import boto3

bucket = "<your_bucket"
key = "<your_model_prefix>"
boto3.resource('s3').Bucket(bucket).download_file(key, 'model.tar.gz')

os.system('tar -zxvf model.tar.gz')

# Linear learner model is itself a zip file, containing a mxnet model and other metadata.
# First unzip the model.
os.system('unzip model_algo-1') 

# Load the mxnet module
mod = mx.module.Module.load("mx-mod", 0)

# model's weights
mod._arg_params['fc0_weight'].asnumpy().flatten()

# model bias
mod._arg_params['fc0_bias'].asnumpy().flatten()

Upvotes: 3

Related Questions