Example Hello World

All of these examples assume you have access to a Yhat instance (either cloud or enterprise) and a Yhat username and apikey. You'll also need to have the Yhat client library installed $ pip install -U yhat, or see Installation.

Deploying Your First Model

Open a file and paste in the following:

from yhat import Yhat, YhatModel , preprocess

class HelloWorld(YhatModel):
    @preprocess(in_type=dict, out_type=dict) 
    def execute(self, data):
        me = data['name']
        greeting = "Hello " + str(me) + "!"
        return { "greeting": greeting }

yh = Yhat("YOUR_USERNAME", "YOUR_APIKEY", "http://cloud.yhathq.com/")
yh.deploy  ("HelloWorld", HelloWorld, globals())

Great! You just deployed your first model. Now let's actually use it.

Calling Your First Model

This is your connection to the ŷhat server.

yh = Yhat("YOUR_USERNAME", "YOUR_APIKEY", "http://cloud.yhathq.com/")
yh.predict ("HelloWorld", {"name": "Hank"})

Calling from curl

    -H "Content-Type: application/json" \
    --data '{"name": "Hank"}' \