Skip to main content

Python client for Yhat (http://yhathq.com/)

Project description

This is the connection to the Yhat API. If you’d like to read more, visit our docs.

Table of Contents:

Quickstart

You can download the example here , or clone the git repo.

$ git clone git@github.com:yhat/yhat-examples.git
$ cd beer-recommender

Insert your APIKEY and USERNAME and run the script.

$ python recommender.py
Deploy? (y/N): y
# {"status": "success"}

Installation

Using pip:

$ pip install --upgrade yhat

From source:

$ git clone git@github.com:yhat/yhat-client.git
$ cd yhat-client
$ python setup.py install

Overview

Handling Input and Output

df to df

Specify df to df by decorating execute with the following:

from yhat import preprocess
# ...
# ...
@preprocess(in_type=pd.DataFrame, out_type=pd.DataFrame)
def execute(self, data)
# ...
# ...

Input

// making 1 prediction with an API call
{
  "column1": VALUE,
  "column2": VALUE
}
// making multiple predictions with 1 API call
{
  "column1": [ VALUE_1, VALUE_2 ]
  "column2": [ VALUE_1, VALUE_2 ]
}

Output

Data will come back with columns as keys and values as lists of values.

{
  "output_column1": [ VALUE_1 ],
  "output_column2": [ VALUE_1 ]
}

df to dict

from yhat import preprocess
# ...
# ...
@preprocess(in_type=pd.DataFrame, out_type=dict)
def execute(self, data)
# ...
# ...

Input

// making 1 prediction with an API call
{
  "column1": VALUE,
  "column2": VALUE
}
// making multiple predictions with 1 API call
{
  "column1": [ VALUE_1, VALUE_2 ]
  "column2": [ VALUE_1, VALUE_2 ]
}

Output

Selecting the dict output gives the user the ability to define their own output format (so long as it is a valid Python dictionary.

// this is valid
{
  "pred": 1
  "values": [1, 2, 3]
}
// this is also valid
{
  "x": {
    "y": 10
  "z": 100
  }
}

dict to dict

This is the most “free form” means of input and output. The user can send in any valid dictionary, process it how they like, and then return any valid dictionary .

from yhat import preprocess
# ...
# ...
@preprocess(in_type=dict, out_type=dict)
def execute(self, data)
# ...
# ...

Input

// this is valid
{
  "pred": 1
  "values": [1, 2, 3]
}
// this is also valid
{
  "x": {
    "y": 10
  },
    "z": 100
  }
}

Output

// this is valid
{
  "pred": 1
  "values": [1, 2, 3]
}
// this is also valid
{
  "x": {
    "y": 10
  },
    "z": 100
  }
}

Deploying

>>> yh.deploy("myExampleModel", MyExampleModel, globals())

Examples

yhat-cli

Usage

yhat-cli config [--reset]
yhat-cli models [--admin]
yhat-cli model <modelname>
yhat-cli (-h | --help)
yhat-cli (-v | --version)

config [--reset]

Configure the yhat client with your API credentials. The option --reset will reset your credentials.

models

Return the models for your account. The option --admin returns all models on the server, you must have admin access for this.

model <modelname>

Returns details about the given model. You must own this model to view it.

Dependencies

Required

  • doctopt

  • progressbar

  • pip

  • Flask

  • colorama

  • websocket-client

  • ElasticTabstops

  • dill

Highly suggested

  • pandas

  • sklearn

Analytics

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yhat-1.2.5.tar.gz (21.8 kB view details)

Uploaded Source

File details

Details for the file yhat-1.2.5.tar.gz.

File metadata

  • Download URL: yhat-1.2.5.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for yhat-1.2.5.tar.gz
Algorithm Hash digest
SHA256 8911e43e926a137614c80670a29d4fee958a5b9a0bb5807674e0965707590dac
MD5 e27644787838c73b9ca668f3526250bc
BLAKE2b-256 7ed4d8e27f0ad0fcced62da47d4b0cdd397f58545f4b00b4669512f6869dc6bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page