Comments (3)
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.
Just to add:
# get prediction response
json_prediction = predictor.predict(request_data)
prediction_2010 = decode_prediction(json_prediction)
from ml_sagemaker_studies.
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)
- language support ua HOT 3
- With "sagemaker 2.31.1", "sagemaker.pytorch.PyTorch" needs to specify both "framework_version" and "py_version" HOT 1
- as_matrix deprecated in pandas, throwing error HOT 1
- 1_Data_Exploration: UsageError: Line magic function `%` not found. HOT 3
- make_time_series should use pd.date_range HOT 4
- Redundunt Lines in Project_Plagiarism_Detection Notebook 3 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ml_sagemaker_studies.