Skip to content

Instantly share code, notes, and snippets.

@glamp
Created September 13, 2016 14:26
Show Gist options
  • Save glamp/a51c76e9c2a341140a1cf183e2344204 to your computer and use it in GitHub Desktop.
Save glamp/a51c76e9c2a341140a1cf183e2344204 to your computer and use it in GitHub Desktop.
from yhat import Yhat, YhatModel
import numpy as np
class SplitTestExample(YhatModel):
def execute(self, data):
# randomly select model to use. `p` defines the split percentage
endpoints = ["ModelA", "ModelB"]
endpoint = np.random.choice(endpoints, p=[0.2, 0.8])
# make prediction to a "sub-model". this will give you back the full API response
response = yh.predict(endpoint, data)
# format the results and return. we're only going to grab the 'result' value
# from the API response
output = response['result']
# assign a label for which endpoint/variant was used, and then return the output
output['variant'] = endpoint
return output
yh = Yhat(USERNAME, APIKEY, URL)
yh.deploy("SplitTestSuperModel", SplitTestExample, globals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment