Module: NexosisApi::Client::Models
- Included in:
- NexosisApi::Client
- Defined in:
- lib/nexosis_api/client/models.rb
Overview
class to operate on model endpoint in Nexosis API
Instance Method Summary collapse
-
#get_model(model_id) ⇒ NexosisApi::ModelSummary
Get the details of the particular model requested by id.
-
#list_models(datasource_name = nil, page = 0, page_size = 50, query_options = {}) ⇒ NexosisApi::PagedArray of NexosisApi::ModelSummary
List all models created in your company, optionally filtered by query parameters.
-
#predict(model_id, feature_data) ⇒ NexosisApi::PredictResponse
Run a feature set through the model to get predictions.
-
#remove_model(model_id) ⇒ Object
Remove an existing model.
-
#remove_models(datasource_name = nil, begin_date = nil, end_date = nil) ⇒ Object
Deletes multiple models based on the provided filter criteria.
Instance Method Details
permalink #get_model(model_id) ⇒ NexosisApi::ModelSummary
Get the details of the particular model requested by id
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nexosis_api/client/models.rb', line 37 def get_model(model_id) raise ArgumentError, 'Retrieving a model requires that model_id be specified and it is currently null.' if model_id.nil? model_url = "/models/#{model_id}" response = self.class.get(model_url, @options) if (response.success?) NexosisApi::ModelSummary.new(response.parsed_response) else raise HttpException.new("There was a problem getting your model: #{response.code}.", "Could not get model #{model_id}", response) end end |
permalink #list_models(datasource_name = nil, page = 0, page_size = 50, query_options = {}) ⇒ NexosisApi::PagedArray of NexosisApi::ModelSummary
-
query options dates can either be ISO 8601 compliant strings or Date objects
List all models created in your company, optionally filtered by query parameters
models created for this data source name.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nexosis_api/client/models.rb', line 13 def list_models(datasource_name = nil, page = 0, page_size = 50, = {}) model_url = '/models' query = { page: page, pageSize: page_size } unless .empty? query.store('createdBeforeDate', ['end_date']) unless ['end_date'].nil? query.store('createdAfterDate', ['begin_date']) unless ['begin_date'].nil? end query.store(dataSourceName: datasource_name) unless datasource_name.nil? response = self.class.get(model_url, headers: @headers, query: query) raise HttpException.new("There was a problem listing models: #{response.code}.", "listing models with data source name #{datasource_name}", response) unless response.success? NexosisApi::PagedArray.new(response.parsed_response, response.parsed_response['items'] .map { |item| NexosisApi::ModelSummary.new(item) }) end |
permalink #predict(model_id, feature_data) ⇒ NexosisApi::PredictResponse
The feature data shape should match that of the dataset used to create the model.
Run a feature set through the model to get predictions
Any missing features in this request will reduce the quality of the predictions.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nexosis_api/client/models.rb', line 55 def predict(model_id, feature_data) raise ArgumentError, 'Running predictions requires that model_id be specified and it is currently empty.' if model_id.empty? raise ArgumentError, 'Running predictions requires that feature_data be specified and it is currently empty.' if feature_data.empty? predict_url = "/models/#{model_id}/predict" response = self.class.post(predict_url, headers: @headers, body: { "data": feature_data }.to_json) if (response.success?) NexosisApi::PredictResponse.new(model_id, response.parsed_response) else raise HttpException.new("There was a problem predicting from your model: #{response.code}.", "Could not start predict for #{model_id}", response) end end |
permalink #remove_model(model_id) ⇒ Object
Remove an existing model
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nexosis_api/client/models.rb', line 72 def remove_model(model_id) raise ArgumentError, 'Deleting a model requires that model_id be specified and it is currently empty.' if model_id.empty? delete_url = "/models/#{model_id}" response = self.class.delete(delete_url, @options) unless (response.success?) raise HttpException.new("There was a problem deleting your model: #{response.code}.", "Could not delete #{model_id}", response) end end |
permalink #remove_models(datasource_name = nil, begin_date = nil, end_date = nil) ⇒ Object
-
Use with great care. This permanently removes trained models.
Deletes multiple models based on the provided filter criteria. All parameters are indepdently optional, but one must be sent.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/nexosis_api/client/models.rb', line 89 def remove_models(datasource_name = nil, begin_date = nil, end_date = nil) params_unset = datasource_name.nil? params_unset &= begin_date.nil? params_unset &= end_date.nil? raise ArgumentError, 'Must set one of the method parameters.' if params_unset delete_url = '/models' query = {} query.store('dataSourceName', datasource_name) unless datasource_name.nil? query.store('createdAfterDate', begin_date) unless begin_date.nil? query.store('createdBeforeDate', end_date) unless end_date.nil? response = self.class.delete(delete_url, headers: @headers, query: query) unless (response.success?) raise HttpException.new("There was a problem deleting your models: #{response.code}.", 'Could not delete models', response) end end |