Class: Wise::Project
- Inherits:
-
Object
- Object
- Wise::Project
- Defined in:
- lib/wise/project.rb
Instance Method Summary collapse
-
#initialize(path, options = {}) ⇒ Project
constructor
Creates a project handle for an existing wise.io project.
-
#predict(model, f, raw = false) ⇒ Object
Makes predictions on a model in the project.
Constructor Details
#initialize(path, options = {}) ⇒ Project
Creates a project handle for an existing wise.io project.
Parameters:
- path
-
The project path (e.g. ‘robin/quasars’).
- options
-
See below.
Options:
- address
-
The base address to connect to; defaults to wise.io.
- user
-
Username used for authentication.
- password
-
Password used for authentication.
Note that user and password can be omitted if a wise.io profile is set up; if user and password are given as options, however, the profile is ignored.
50 51 52 |
# File 'lib/wise/project.rb', line 50 def initialize path, = {} @client = Client.new path, end |
Instance Method Details
#predict(model, f, raw = false) ⇒ Object
Makes predictions on a model in the project.
Parameters
- model
-
The model label or id.
- f
-
The data for the model to predict - this may take several forms:
-
If f is a String corresponding to a path to a file, the contents of the file is used as the input; this is expected to be in a CSV format compatible with the model.
-
If f is an open File, its contents is used as input as above.
-
If f is a Hash, it is interpreted as a selection. See the selection API for more information.
-
- raw
-
If true, returns the result as raw CSV data rather than as an array.
Returns
The predictions for the data as an array.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/wise/project.rb', line 73 def predict model, f, raw = false params = {} content_type = "text/csv" if (f.is_a? String) && (File.exists? File.join(Dir.pwd, f)) data = File.read(f) elsif (f.is_a? File) && !f.closed? data = f.read elsif (f.is_a? Hash) && !f[:dataset].nil? dataset = f.delete(:dataset) data = f.to_json params = {:dataset_id => (@client.dataset_id dataset)} content_type = "application/json" else data = f end m_id = @client.model_id model resp = @client.resource("model/#{m_id}/predict").get(:payload => data, :params => params, :content_type => content_type) raw ? resp : CSV.parse(resp, :converters => [:float]) end |