Module: NexosisApi::Client::Sessions
- Included in:
- NexosisApi::Client
- Defined in:
- lib/nexosis_api/client/sessions.rb
Overview
Session-based API operations
Instance Method Summary collapse
-
#create_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil) ⇒ NexosisApi::SessionResponse
Initiate a new forecast session based on a named dataset.
-
#create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil) ⇒ NexosisApi::SessionResponse
Analyze impact for an event with data already saved to the API.
-
#create_model(datasource_name, target_column, columns = {}, options = { prediction_domain: 'regression' }) ⇒ Object
Create a new model based on a data source.
-
#get_confusion_matrix(session_id) ⇒ NexosisApi::ClassifierResult
Get the confusion matrix for a completed classification session.
-
#get_session(session_id) ⇒ NexosisApi::Session
Get a specific session by id.
-
#get_session_results(session_id, as_csv = false, prediction_interval = nil) ⇒ NexosisApi::SessionResult
Get the results of the session.
-
#list_sessions(query_options = {}, page = 0, pageSize = 50) ⇒ NexosisApi::PagedArray of NexosisApi::SessionResponse
List sessions previously submitted.
-
#remove_session(session_id) ⇒ Object
Remove a session.
-
#remove_sessions(query_options = {}) ⇒ Object
Remove sessions that have been run.
Instance Method Details
permalink #create_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil) ⇒ NexosisApi::SessionResponse
The time interval selected must be greater than or equal to the finest granularity of the data provided. For instance if your data includes many recoreds per hour, then you could request hour, day, or any other result interval. However, if your data includes only a few records per day or fewer, then a request for an hourly result interval will produce poor results.
Initiate a new forecast session based on a named dataset.
80 81 82 |
# File 'lib/nexosis_api/client/sessions.rb', line 80 def create_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, = nil) create_session(dataset_name, start_date, end_date, target_column, nil, 'forecast', result_interval, ) end |
permalink #create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil) ⇒ NexosisApi::SessionResponse
Analyze impact for an event with data already saved to the API.
94 95 96 |
# File 'lib/nexosis_api/client/sessions.rb', line 94 def create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, = nil) create_session(dataset_name, start_date, end_date, target_column, event_name, 'impact', result_interval, ) end |
permalink #create_model(datasource_name, target_column, columns = {}, options = { prediction_domain: 'regression' }) ⇒ Object
-
classifcation assumes balanced classes. The use of a ‘balanced=false’ option
Create a new model based on a data source
indicates that no attempt should be made to sample the classes in balanced fashion.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/nexosis_api/client/sessions.rb', line 139 def create_model(datasource_name, target_column, columns = {}, = { prediction_domain: 'regression' }) model_url = '/sessions/model' body = { dataSourceName: datasource_name, targetColumn: target_column, predictionDomain: [:prediction_domain].downcase } body.store(:extraParameters, { balance: [:balance] }) if .include?(:balance) && body[:predictionDomain] == 'classification' body.store(columns: columns) unless columns.empty? response = self.class.post(model_url, headers: @headers, body: body.to_json) if response.success? session_hash = { 'session' => response.parsed_response }.merge(response.headers) NexosisApi::SessionResponse.new(session_hash) else raise HttpException.new("There was a problem creating the model session: #{response.code}.", 'creating model session' ,response) end end |
permalink #get_confusion_matrix(session_id) ⇒ NexosisApi::ClassifierResult
-
This endpoint returns a 404 for requests of non-classification sessions
Get the confusion matrix for a completed classification session
162 163 164 165 166 167 |
# File 'lib/nexosis_api/client/sessions.rb', line 162 def get_confusion_matrix(session_id) result_url = "/sessions/#{session_id}/results/confusionmatrix" response = self.class.get(result_url, headers: @headers) raise HttpException.new("There was a problem getting a confusion matrix for session #{session_id}", 'getting confusion matrix', response) unless response.success? NexosisApi::ClassifierResult.new(response.parsed_response) end |
permalink #get_session(session_id) ⇒ NexosisApi::Session
Get a specific session by id.
123 124 125 126 127 128 |
# File 'lib/nexosis_api/client/sessions.rb', line 123 def get_session(session_id) session_url = "/sessions/#{session_id}" response = self.class.get(session_url, @options) return NexosisApi::Session.new(response.parsed_response) if response.success? raise HttpException.new("There was a problem getting the session: #{response.code}.", "getting session #{session_id}" ,response) end |
permalink #get_session_results(session_id, as_csv = false, prediction_interval = nil) ⇒ NexosisApi::SessionResult
Get the results of the session.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/nexosis_api/client/sessions.rb', line 104 def get_session_results(session_id, as_csv = false, prediction_interval = nil) session_result_url = "/sessions/#{session_id}/results" @headers['Accept'] = 'text/csv' if as_csv query = { predictionInterval: prediction_interval } unless prediction_interval.nil? response = self.class.get(session_result_url, headers: @headers, query: query) @headers.delete('Accept') if (response.success?) return response.body if as_csv NexosisApi::SessionResult.new(response.parsed_response) else raise HttpException.new("There was a problem getting the session: #{response.code}.", "get results for session #{session_id}" ,response) end end |
permalink #list_sessions(query_options = {}, page = 0, pageSize = 50) ⇒ NexosisApi::PagedArray of NexosisApi::SessionResponse
query parameters hash members are dataset_name, event_name, requested_before_date, and requested_after_date. After and before dates refer to the session requested date.
List sessions previously submitted
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nexosis_api/client/sessions.rb', line 21 def list_sessions( = {}, page = 0, pageSize = 50) sessions_url = '/sessions' query = { 'dataSetName' => [:dataset_name], 'eventName' => [:event_name], 'requestedAfterDate' => [:requested_after_date], 'requestedBeforeDate' => [:requested_before_date], 'type' => [:type], 'page' => page, 'pageSize' => pageSize } response = self.class.get(sessions_url, headers: @headers, query: query) raise HttpException.new('Could not retrieve sessions', "Get all sessions with query #{}", response) unless response.success? NexosisApi::PagedArray.new(response.parsed_response, response.parsed_response['items'].map do |session_hash| response_hash = { 'session' => session_hash }.merge(response.headers) NexosisApi::SessionResponse.new(response_hash) end) end |
permalink #remove_session(session_id) ⇒ Object
Remove a session
44 45 46 47 48 49 50 51 52 |
# File 'lib/nexosis_api/client/sessions.rb', line 44 def remove_session(session_id) if (session_id.to_s.empty?) raise ArgumentError 'session_id cannot be empty or nil' end session_url = "/sessions/#{session_id}" response = self.class.delete(session_url, headers: @headers) return if response.success? raise HttpException.new('Could not delete session with given id', "remove session with id #{session_id}", response) end |
permalink #remove_sessions(query_options = {}) ⇒ Object
query parameters hash members are type, dataset_name, event_name, start_date, and end_date. Start and end dates refer to the session requested date. Results are not removed but then can only be accessed by dataset name
Remove sessions that have been run. All query options are optional and will be used to limit the sessions removed.
61 62 63 64 65 66 |
# File 'lib/nexosis_api/client/sessions.rb', line 61 def remove_sessions( = {}) sessions_url = '/sessions' response = self.class.delete(sessions_url, :headers => @headers, :query => ()) return if response.success? raise HttpException.new('Could not remove sessions', "Remove sessions with query #{.to_s}",response) end |