Code Monkey home page Code Monkey logo

Comments (3)

p1nox avatar p1nox commented on August 15, 2024 2

Probably @plbalmeida already sorted out this issue, but just to have the reference here, the solution is related to: aws/sagemaker-python-sdk#1126 (comment) .

from sagemaker.deserializers import JSONDeserializer
from sagemaker.serializers import JSONSerializer

predictor = estimator.deploy(
    initial_instance_count=1,
    instance_type='ml.t2.medium',
    # content_type="application/json" # specify that it will accept/produce JSON
    serializer=JSONSerializer(),
    deserializer=JSONDeserializer()
)

Also, in the subsequent json_predictor_input() fn, one should return request_data directly because predictor it's already defined to accept a JSON objects.

def json_predictor_input(input_ts, num_samples=50, quantiles=['0.1', '0.5', '0.9']):
    '''Accepts a list of input time series and produces a formatted input.
       :input_ts: An list of input time series.
       :num_samples: Number of samples to calculate metrics with.
       :quantiles: A list of quantiles to return in the predicted output.
       :return: The JSON-formatted input.
       '''
    # request data is made of JSON objects (instances)
    # and an output configuration that details the type of data/quantiles we want
    
    instances = []
    for k in range(len(input_ts)):
        # get JSON objects for input time series
        instances.append(series_to_json_obj(input_ts[k]))

    # specify the output quantiles and samples
    configuration = {"num_samples": num_samples, 
                     "output_types": ["quantiles"], 
                     "quantiles": quantiles}

    request_data = {"instances": instances, 
                    "configuration": configuration}
    
    # not needed
    # json_request = json.dumps(request_data).encode('utf-8')
    
    return request_data

And finally, there's no need to decode prediction string result json_prediction in decode_prediction() fn, because it's already a JSON object.

def decode_prediction(prediction_data):
    '''Accepts a JSON prediction and returns a list of prediction data.
    '''
    prediction_list = []
    for k in range(len(prediction_data['predictions'])):
        prediction_list.append(pd.DataFrame(data=prediction_data['predictions'][k]['quantiles']))
    return prediction_list

from ml_sagemaker_studies.

furyhawk avatar furyhawk commented on August 15, 2024 1

Just to add:

# get prediction response
json_prediction = predictor.predict(request_data)

prediction_2010 = decode_prediction(json_prediction)

from ml_sagemaker_studies.

ronny-udacity avatar ronny-udacity commented on August 15, 2024

Please feel free to post your question on https://knowledge.udacity.com/ so the mentors can help look into your codes and resolve the error.

from ml_sagemaker_studies.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.