This scenario can come up if you have a lot of parameters (say 20+ predictors) that you want to pass to your Model API and don't want to explicitly list those out to your Model API function. Here's how you can set this up:
Sample model code:
import pandas as pd def predict(multiparams): input_df = pd.DataFrame.from_dict(multiparams, orient='index') ''' code to parse input dataframe and utilize the parameter values ''' return input_df.to_json()
In the above sample code, multiparams
is a python dict that can essentially hold all/any number of parameters, be passed to the Model API via JSON (in the below form) and converted to a Pandas DataFrame using the from_dict
method for further use.
Deploy the above code as a Model API and test it in the tester block on the published Model API page by
(a) passing just 2 params
{ "data": { "multiparams": { "first": 100, "second": 200 } } }
response received:
(b) passing 3 params
{ "data": { "multiparams": { "first": 100, "second": 200, "third": 300 } } }
response received:
Comments
0 comments
Please sign in to leave a comment.