Hello World

All of these examples assume you have access to a Yhat instance (either through the public sandbox or enterprise) and a Yhat username and apikey.

You'll also need to add the Yhat client library for either R or Python, which is shown below:

$ pip install -U yhat
install.packages("yhatr")

To deploy our model, simply copy the script below, paste it in your R or Python session, edit the USERNAME and APIKEY fields, and run the script!

library(yhatr)

model.predict <- function(request) {
  me <- request$name
  greeting <- paste ("Hello", me, "!")
  greeting
}

yhat.config  <- c(
  username="YOUR_USERNAME",
  apikey="YOUR_APIKEY",
  env="https://sandbox.yhathq.com/"
)
yhat.deploy("HelloWorld",confirm = FALSE)
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", "https://sandbox.yhathq.com/")
yh.deploy("HelloWorld", HelloWorld, globals())

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

Be sure to check out the REST API section on how to embed predictive models into web applications!

yh = Yhat("YOUR_USERNAME", "YOUR_APIKEY", "https://sandbox.yhathq.com/")
yh.predict("HelloWorld", {"name": "Hank"})
testdata <- rjson::fromJSON('{"name":"hank"}')
yhat.predict("HelloWorld", testdata)

results matching ""

    No results matching ""