Class: Yhat
- Inherits:
-
Object
- Object
- Yhat
- Defined in:
- lib/yhat.rb
Instance Method Summary collapse
-
#initialize(username, apikey, uri = 'api.yhathq.com') ⇒ Yhat
constructor
Class that can be used to access the Yhat API.
-
#predict(modelname, data) ⇒ Hash
Make a prediction by calling Yhat via HTTP.
Constructor Details
#initialize(username, apikey, uri = 'api.yhathq.com') ⇒ Yhat
Class that can be used to access the Yhat API
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/yhat.rb', line 8 def initialize(username, apikey, uri = 'api.yhathq.com') @username = username @apikey = apikey @base_uri = uri if @base_uri == 'api.yhathq.com' @is_enterprise = false else @is_enterprise = true end end |
Instance Method Details
#predict(modelname, data) ⇒ Hash
Make a prediction by calling Yhat via HTTP. You should pass both the name of the model you want to use to make a prediction as well as a JSON object (or a Hash) that contains the data requried to make a prediction.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/yhat.rb', line 29 def predict(modelname, data) uri = URI.parse(@base_uri) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new("/models/" + modelname + "/") request.add_field('Content-Type', 'application/json') request.body = data response = http.request(request) data = response.body JSON.parse(data) end |