nexosis_api 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c526af7e9fcefc72090c15c425122bdcb1d84ad
4
- data.tar.gz: d8b6c9a510f6c709f1d30cf4a7e63bd9864730cb
3
+ metadata.gz: a8f386ea632449db904147f0f38b1fbb113633ef
4
+ data.tar.gz: c6afea0f24270d210be6fea0efa8e8e99be6b6fb
5
5
  SHA512:
6
- metadata.gz: bbfdbdc1f4da07c9ce8c88c7410ac483929ab07cd298906a31fb60395d5ed39a71c7609d3d69a705c2fba12c39de2102d8420d47ea3077efb6d20e4191e9232d
7
- data.tar.gz: c17bdd00ea6712696f731b46193bcb6cd16f9a0f32bbe2c4cbb9e8fb8542e98ae8b13d21fbca517ddbb80c4892380b838215429a407eacbdaa076a51bcc0d0b2
6
+ metadata.gz: 27fcb7d85fe04fb158a52e2c1dc76f438f4bd8b71380b5d8410cd264081086b4038dc2010dc82ba5a84d5fcc46ce95d3a9836699d993997f243207263f794130
7
+ data.tar.gz: 88e9204cdfc9fd40e5ee0532acda9a56c7eb73677c301feb47a47886a0909e8a358fb9aa7fdf726992d6874a461a525901111f4a3db7dfc0a599268c37d0cbbb
@@ -0,0 +1,25 @@
1
+ require 'nexosis_api/session'
2
+ module NexosisApi
3
+ # class to hold parsed results of confusion matrix request
4
+ # @since 1.4.1
5
+ class ClassifierResult < Session
6
+ def initialize(classify_result)
7
+ classify_result.each do |k, v|
8
+ if (k.to_s == 'confusionMatrix')
9
+ @confusion_matrix = v
10
+ elsif (k.to_s == 'classes')
11
+ @classes = v
12
+ end
13
+ end
14
+ super(classify_result)
15
+ end
16
+
17
+ # array of arrays to form confusion matrix results
18
+ # @return [Array of Array of Int] - the class counts for expected to predicted
19
+ attr_accessor :confusion_matrix
20
+
21
+ # Class labels in index order of matrix arrays
22
+ # @return [Array]
23
+ attr_accessor :classes
24
+ end
25
+ end
@@ -2,6 +2,7 @@ require 'nexosis_api/algorithm_run'
2
2
  require 'nexosis_api/algorithm_selection'
3
3
  require 'nexosis_api/algorithm'
4
4
  require 'nexosis_api/calendar_jointarget'
5
+ require 'nexosis_api/classifier_result'
5
6
  require 'nexosis_api/column'
6
7
  require 'nexosis_api/column_options'
7
8
  require 'nexosis_api/column_role'
@@ -15,6 +16,7 @@ require 'nexosis_api/impact_metric'
15
16
  require 'nexosis_api/imports_response'
16
17
  require 'nexosis_api/join'
17
18
  require 'nexosis_api/link'
19
+ require 'nexosis_api/message'
18
20
  require 'nexosis_api/metric'
19
21
  require 'nexosis_api/model_summary'
20
22
  require 'nexosis_api/paged_array'
@@ -157,15 +157,19 @@ module NexosisApi
157
157
  # @param datasource_name [String] The datasource from which to build the model
158
158
  # @param target_column [String] The column which will be predicted when using the model
159
159
  # @param columns [Hash] column metadata to modify roles, imputation, or target.
160
+ # @param options [Hash] prediction_domain and or balanced indicator for classification
161
+ # @note - classifcation assumes balanced classes. The use of a 'balanced=false' option
162
+ # indicates that no attempt should be made to sample the classes in balanced fashion.
160
163
  # @since 1.3.0
161
- def create_model(datasource_name, target_column, columns = {})
164
+ def create_model(datasource_name, target_column, columns = {}, options = { prediction_domain: 'regression' })
162
165
  model_url = '/sessions/model'
163
166
  body = {
164
167
  dataSourceName: datasource_name,
165
168
  targetColumn: target_column,
166
- predictionDomain: 'regression',
169
+ predictionDomain: options[:prediction_domain].downcase,
167
170
  isEstimate: false
168
171
  }
172
+ body.store(:balance, options[:balance]) if options.include?(:balance) && body[:predictionDomain] == 'classification'
169
173
  body.store(columns: columns) unless columns.empty?
170
174
  response = self.class.post(model_url, headers: @headers, body: body.to_json)
171
175
  if response.success?
@@ -176,6 +180,18 @@ module NexosisApi
176
180
  end
177
181
  end
178
182
 
183
+ # Get the confusion matrix for a completed classification session
184
+ # @param session_id [String] The unique id of the completed classification session
185
+ # @return [NexosisApi::ClassifierResult] a confusion matrix along with class labels and other session information.
186
+ # @since 1.4.1
187
+ # @note - This endpoint returns a 404 for requests of non-classification sessions
188
+ def get_confusion_matrix(session_id)
189
+ result_url = "/sessions/#{session_id}/results/confusionmatrix"
190
+ response = self.class.get(result_url, headers: @headers)
191
+ raise HttpException.new("There was a problem getting a confusion matrix for session #{session_id}", 'getting confusion matrix', response) unless response.success?
192
+ NexosisApi::ClassifierResult.new(response.parsed_response)
193
+ end
194
+
179
195
  private
180
196
 
181
197
  # @private
@@ -205,7 +221,7 @@ module NexosisApi
205
221
  session_hash = { 'session' => response.parsed_response }.merge(response.headers)
206
222
  NexosisApi::SessionResponse.new(session_hash)
207
223
  else
208
- raise HttpException.new("Unable to create new #{type} session", "Create session for dataset #{dataset_name}",response)
224
+ raise HttpException.new("Unable to create new #{type} session", "Create session for dataset #{dataset_name}", response)
209
225
  end
210
226
  end
211
227
 
@@ -0,0 +1,19 @@
1
+ module NexosisApi
2
+ # class to provide message responses
3
+ # @since 1.4.1
4
+ class Message
5
+ def initialize(message_hash)
6
+ message_hash.each do |k,v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ end
10
+
11
+ # The type of message: information, warning, or error
12
+ # @return [String]
13
+ attr_accessor :severity
14
+
15
+ # The content of the message
16
+ # @return [String]
17
+ attr_accessor :message
18
+ end
19
+ end
@@ -8,7 +8,8 @@ module NexosisApi
8
8
  'sessionId' => :@session_id,
9
9
  'availablePredictionIntervals' => :@prediction_intervals,
10
10
  'startDate' => :@start_date,
11
- 'endDate' => :@end_date }
11
+ 'endDate' => :@end_date,
12
+ 'predictionDomain' => :@prediction_domain }
12
13
  session_hash.each do |k, v|
13
14
  if (k == 'links')
14
15
  @links = v.map { |l| NexosisApi::Link.new(l) }
@@ -19,6 +20,8 @@ module NexosisApi
19
20
  end
20
21
  elsif (k == 'requestedDate')
21
22
  @requested_date = DateTime.parse(v)
23
+ elsif (k == 'messages')
24
+ @messages = v.map { |m| NexosisApi::Message.new(m) } unless v.empty?
22
25
  else
23
26
  instance_variable_set("@#{k}", v) unless v.nil?
24
27
  end
@@ -121,5 +124,20 @@ module NexosisApi
121
124
  # this list for other intervals which can be requested.
122
125
  # @since 1.4.0
123
126
  attr_accessor :prediction_intervals
127
+
128
+ # The type of model if a model creation session
129
+ # @return [String]
130
+ # @since 1.4.1
131
+ attr_accessor :prediction_domain
132
+
133
+ # A list of warning or error messages optionally returned from session
134
+ # @return [Array of Message]
135
+ attr_accessor :messages
136
+
137
+ # Whether classes were sampled as balanced in the context of a classification model
138
+ # @return [Boolean]
139
+ # @note - the default is true and has no means outside of classification
140
+ # @since 1.4.1
141
+ attr_accessor :balance
124
142
  end
125
143
  end
@@ -11,6 +11,8 @@ module NexosisApi
11
11
  instance_variable_set('@cost', v[0]) unless v.nil?
12
12
  elsif(k == 'nexosis-account-balance')
13
13
  instance_variable_set('@account_balance', v[0]) unless v.nil?
14
+ elsif(k == 'balance')
15
+ @balance = v
14
16
  end
15
17
  end
16
18
  end
data/nexosisapi.gemspec CHANGED
@@ -16,6 +16,6 @@ Gem::Specification.new do |spec|
16
16
  spec.require_paths = ['lib']
17
17
  spec.required_ruby_version = '>= 2.0.0'
18
18
  spec.summary = "Ruby client for working with the Nexosis API"
19
- spec.version = '1.4.0'
19
+ spec.version = '1.4.1'
20
20
  spec.metadata["yard.run"] = "yri"
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexosis_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nexosis,Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-09 00:00:00.000000000 Z
11
+ date: 2017-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,6 +50,7 @@ files:
50
50
  - lib/nexosis_api/algorithm_run.rb
51
51
  - lib/nexosis_api/algorithm_selection.rb
52
52
  - lib/nexosis_api/calendar_jointarget.rb
53
+ - lib/nexosis_api/classifier_result.rb
53
54
  - lib/nexosis_api/client.rb
54
55
  - lib/nexosis_api/client/datasets.rb
55
56
  - lib/nexosis_api/client/imports.rb
@@ -69,6 +70,7 @@ files:
69
70
  - lib/nexosis_api/imports_response.rb
70
71
  - lib/nexosis_api/join.rb
71
72
  - lib/nexosis_api/link.rb
73
+ - lib/nexosis_api/message.rb
72
74
  - lib/nexosis_api/metric.rb
73
75
  - lib/nexosis_api/model_summary.rb
74
76
  - lib/nexosis_api/paged_array.rb