nexosis_api 2.3.0 → 2.4.0
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 +5 -5
- data/lib/nexosis_api/anomaly_distances.rb +16 -0
- data/lib/nexosis_api/client.rb +5 -0
- data/lib/nexosis_api/client/sessions.rb +55 -3
- data/lib/nexosis_api/distance_metric.rb +24 -0
- data/lib/nexosis_api/feature_importance.rb +12 -0
- data/lib/nexosis_api/outlier.rb +28 -0
- data/lib/nexosis_api/session.rb +7 -1
- data/lib/nexosis_api/timeseries_outliers.rb +18 -0
- data/lib/nexosis_api/vocabulary_summary.rb +1 -1
- data/nexosisapi.gemspec +2 -2
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b203efa8f3451eb665f2f55c6e608305d4f4b0f8173289eca997fbea0ce6b569
|
4
|
+
data.tar.gz: 5c154fb6ec0124f977959279fc520855c4427adeadc24acc7e7eb82b27cbfc67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53eaabf7b732f7122e064203fed2f3d80fa6ebad81da13d2dc36ca05531558ba909a8de5ac3a0664f7065841899358609950a34fcb30bb9b3ef67392548c11f2
|
7
|
+
data.tar.gz: bf05c4eaebb1ead6cf124c3546636af8e08f9163fcb92de05c8fde5db87e52209e66325fd68f9790492dcdaea5112baea5ad7bc8c2bcda00b3fc541dbda4d948
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'nexosis_api/session_response'
|
2
|
+
module NexosisApi
|
3
|
+
# class to hold parsed results of distance metric request
|
4
|
+
# @since 2.4.0
|
5
|
+
class AnomalyDistances < SessionResponse
|
6
|
+
def initialize(distance_data)
|
7
|
+
data = distance_data.fetch(:data) { |k| distance_data.fetch(k.to_s) }
|
8
|
+
@data = NexosisApi::PagedArray.new(distance_data, data.map { |v| NexosisApi::DistanceMetric.new(v) })
|
9
|
+
super(distance_data.reject { |k, _v| k.to_s.casecmp('data').zero? })
|
10
|
+
end
|
11
|
+
|
12
|
+
# array of metrics providing the distance along with standard anomaly result
|
13
|
+
# @return [NexosisApi::PagedArray NexosisApi::DistanceMetric] - each anomaly score, distance, and the row values
|
14
|
+
attr_reader :data
|
15
|
+
end
|
16
|
+
end
|
data/lib/nexosis_api/client.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'nexosis_api/algorithm_contestant'
|
2
2
|
require 'nexosis_api/algorithm'
|
3
|
+
require 'nexosis_api/anomaly_distances'
|
3
4
|
require 'nexosis_api/anomaly_scores'
|
4
5
|
require 'nexosis_api/calendar_jointarget'
|
5
6
|
require 'nexosis_api/classifier_result'
|
@@ -12,6 +13,8 @@ require 'nexosis_api/dataset_data'
|
|
12
13
|
require 'nexosis_api/dataset_jointarget'
|
13
14
|
require 'nexosis_api/dataset_model'
|
14
15
|
require 'nexosis_api/dataset_summary'
|
16
|
+
require 'nexosis_api/distance_metric'
|
17
|
+
require 'nexosis_api/feature_importance'
|
15
18
|
require 'nexosis_api/http_exception'
|
16
19
|
require 'nexosis_api/impact_metric'
|
17
20
|
require 'nexosis_api/imports_response'
|
@@ -20,6 +23,7 @@ require 'nexosis_api/link'
|
|
20
23
|
require 'nexosis_api/message'
|
21
24
|
require 'nexosis_api/metric'
|
22
25
|
require 'nexosis_api/model_summary'
|
26
|
+
require 'nexosis_api/outlier'
|
23
27
|
require 'nexosis_api/paged_array'
|
24
28
|
require 'nexosis_api/predict_response'
|
25
29
|
require 'nexosis_api/session_contest'
|
@@ -28,6 +32,7 @@ require 'nexosis_api/session_result'
|
|
28
32
|
require 'nexosis_api/session_selection_metrics'
|
29
33
|
require 'nexosis_api/session'
|
30
34
|
require 'nexosis_api/time_interval'
|
35
|
+
require 'nexosis_api/timeseries_outliers'
|
31
36
|
require 'nexosis_api/view_definition'
|
32
37
|
require 'nexosis_api/view_data'
|
33
38
|
require 'nexosis_api/vocabulary_summary'
|
@@ -115,7 +115,7 @@ module NexosisApi
|
|
115
115
|
#
|
116
116
|
# @param session_id [String] the Guid string returned in a previous session request
|
117
117
|
# @param page [Integer] optionally provide a page number for paging. Defaults to 0 (first page).
|
118
|
-
# @param
|
118
|
+
# @param page_size [Integer] optionally provide a page size to limit the total number of results. Defaults to 50, max 1000
|
119
119
|
# @param options [Hash] as_csv [Boolean] to indicate whether results should be returned in csv format; prediction_interval [Float] one of the available prediction intervals for the session.
|
120
120
|
# @return [NexosisApi::SessionResult] SessionResult if parsed, String of csv data otherwise
|
121
121
|
# @raise [NexosisApi::HttpException]
|
@@ -246,14 +246,16 @@ module NexosisApi
|
|
246
246
|
|
247
247
|
# Get the observation class score for a completed classification session
|
248
248
|
# @param session_id [String] The unique id of the completed classification session
|
249
|
+
# @param page_number [Integer] zero-based page number of results to retrieve
|
250
|
+
# @param page_size [Integer] Count of results to retrieve in each page (max 1000).
|
249
251
|
# @return [NexosisApi::ScoreResult] A session result with a list of each observation and score per column.
|
250
252
|
# @raise [NexosisApi::HttpException]
|
251
253
|
# @since 2.1.0
|
252
254
|
# @note - This endpoint returns a 404 for requests of non-classification sessions
|
253
|
-
def get_class_scores(session_id,
|
255
|
+
def get_class_scores(session_id, page_number = 0, page_size = 50)
|
254
256
|
score_url = "/sessions/#{session_id}/results/classScores"
|
255
257
|
query = {
|
256
|
-
page:
|
258
|
+
page: page_number,
|
257
259
|
pageSize: page_size
|
258
260
|
}
|
259
261
|
response = self.class.get(score_url, headers: @headers, query: query)
|
@@ -261,6 +263,56 @@ module NexosisApi
|
|
261
263
|
NexosisApi::ClassifierScores.new(response.parsed_response.merge(response.headers))
|
262
264
|
end
|
263
265
|
|
266
|
+
# Get a feature importance score for each column in the data source used in a session
|
267
|
+
# @param session_id [String] The unique id of the completed session
|
268
|
+
# @param page_number [Integer] zero-based page number of results to retrieve
|
269
|
+
# @param page_size [Integer] Count of results to retrieve in each page (max 1000).
|
270
|
+
# @return [NexosisApi::FeatureImportance]
|
271
|
+
# @since 2.4.0
|
272
|
+
# @note The score returned here is calculated before algorithm selection and so is not algorithm specific. For algorithms
|
273
|
+
# that can return internal scores you need to use the champion endpoints.
|
274
|
+
# @note Those sessions which will provide scores have the supports_feature_importance attribute set True. Others will 404 at this endpoint.
|
275
|
+
def get_feature_importance(session_id, page_number = 0, page_size = 50)
|
276
|
+
importance_url = "/sessions/#{session_id}/results/featureimportance"
|
277
|
+
query = {
|
278
|
+
page: page_number,
|
279
|
+
pageSize: page_size
|
280
|
+
}
|
281
|
+
response = self.class.get(importance_url, headers: @headers, query: query)
|
282
|
+
raise HttpException.new("There was a problem getting the feature importance scores for session #{session_id}", 'getting feature importance', response) unless response.success?
|
283
|
+
NexosisApi::FeatureImportance.new(response.parsed_response.merge(response.headers))
|
284
|
+
end
|
285
|
+
|
286
|
+
# Get per result distance metric for anomaly detection sessions.
|
287
|
+
# @param session_id [String] The unique id of the completed session
|
288
|
+
# @param page_number [Integer] zero-based page number of results to retrieve
|
289
|
+
# @param page_size [Integer] Count of results to retrieve in each page (max 1000).
|
290
|
+
# @return [NexosisApi::AnomalyDistances]
|
291
|
+
# @since 2.4.0
|
292
|
+
# @note This method will return 404 when the session for the given session id does not have a prediction domain of 'anomalies'
|
293
|
+
# @see https://en.wikipedia.org/wiki/Mahalanobis_distance
|
294
|
+
def get_distance_metrics(session_id, page_number = 0, page_size = 50)
|
295
|
+
distance_url = "/sessions/#{session_id}/results/mahalanobisdistances"
|
296
|
+
query = {
|
297
|
+
page: page_number,
|
298
|
+
pageSize: page_size
|
299
|
+
}
|
300
|
+
response = self.class.get(distance_url, headers: @headers, query: query)
|
301
|
+
raise HttpException.new("There was a problem getting the distance metrics for session #{session_id}", 'getting distance metrics', response) unless response.success?
|
302
|
+
NexosisApi::AnomalyDistances.new(response.parsed_response.merge(response.headers))
|
303
|
+
end
|
304
|
+
|
305
|
+
def get_timeseries_outliers(session_id, page_number = 0, page_size = 50)
|
306
|
+
outlier_url = "/sessions/#{session_id}/results/outliers"
|
307
|
+
query = {
|
308
|
+
page: page_number,
|
309
|
+
pageSize: page_size
|
310
|
+
}
|
311
|
+
response = self.class.get(outlier_url, headers: @headers, query: query)
|
312
|
+
raise HttpException.new("There was a problem getting the outliers for session #{session_id}", 'getting outliers', response) unless response.success?
|
313
|
+
NexosisApi::TimeseriesOutliers.new(response.parsed_response.merge(response.headers))
|
314
|
+
end
|
315
|
+
|
264
316
|
private
|
265
317
|
|
266
318
|
# @private
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module NexosisApi
|
2
|
+
# Class to hold the parse results of each 'row' in distance metric response
|
3
|
+
# @since 2.4.0
|
4
|
+
class DistanceMetric
|
5
|
+
def initialize(metric_hash)
|
6
|
+
failover = ->(k) { metric_hash.fetch(k.to_s) }
|
7
|
+
@anomaly_score = metric_hash.fetch(:anomaly, &failover).to_f
|
8
|
+
@distance = metric_hash.fetch(:mahalanobis_distance, &failover).to_f
|
9
|
+
@data = metric_hash.reject { |k, _v| (k.to_s.casecmp('mahalanobis_distance').zero?) || (k.to_s.casecmp('anomaly').zero?) }
|
10
|
+
end
|
11
|
+
|
12
|
+
# The anomaly score determining if this entry is an anomaly
|
13
|
+
# @return [Float]
|
14
|
+
attr_reader :anomaly_score
|
15
|
+
|
16
|
+
# The calculated distance for this row of values
|
17
|
+
# @return [Float]
|
18
|
+
attr_reader :distance
|
19
|
+
|
20
|
+
# The set of values in this row
|
21
|
+
# @return [Hash]
|
22
|
+
attr_reader :data
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module NexosisApi
|
2
|
+
# Class to hold the parse results of a request for Feature Importance scores
|
3
|
+
# @since 2.4.0
|
4
|
+
class FeatureImportance < SessionResponse
|
5
|
+
def initialize(session_hash)
|
6
|
+
@scores = session_hash.fetch(:featureImportance) { |k| session_hash.fetch(k.to_s) }
|
7
|
+
super(session_hash.reject { |k, _v| k.to_s.casecmp('featureimportance').zero? })
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :scores
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module NexosisApi
|
2
|
+
# Class to hold the parse results of an individual outlier for time-series
|
3
|
+
# @note When Nexosis runs a time-series forecast, a smoothed dataset is created in addition
|
4
|
+
# to the original. These outlier values represent those which were modified in that smoothed
|
5
|
+
# dataset.
|
6
|
+
# @since 2.4.0
|
7
|
+
class Outlier
|
8
|
+
def initialize(outlier_hash)
|
9
|
+
match_smooth = ->(k, _v) { !k.match(/:smooth/).nil? }
|
10
|
+
match_actual = ->(k, _v) { !k.match(/:actual/).nil? }
|
11
|
+
@timestamp = DateTime.parse(outlier_hash.fetch(:timeStamp) { |k| outlier_hash.fetch(k.to_s) })
|
12
|
+
@smoothed = outlier_hash.select(&match_smooth).first[1].to_f if outlier_hash.any? &match_smooth
|
13
|
+
@actual = outlier_hash.select(&match_actual).first[1].to_f if outlier_hash.any? &match_actual
|
14
|
+
end
|
15
|
+
|
16
|
+
# Record timestamp for the given target values
|
17
|
+
# @return [DateTime]
|
18
|
+
attr_reader :timestamp
|
19
|
+
|
20
|
+
# The original value for this target
|
21
|
+
# @return [Float]
|
22
|
+
attr_reader :actual
|
23
|
+
|
24
|
+
# The smoothed target used in the smoothed data set
|
25
|
+
# @return [Float]
|
26
|
+
attr_reader :smoothed
|
27
|
+
end
|
28
|
+
end
|
data/lib/nexosis_api/session.rb
CHANGED
@@ -12,7 +12,8 @@ module NexosisApi
|
|
12
12
|
'predictionDomain' => :@prediction_domain,
|
13
13
|
'extraParameters' => :@extra_parameters,
|
14
14
|
'targetColumn' => :@target_column,
|
15
|
-
'statusHistory' => :@status_history
|
15
|
+
'statusHistory' => :@status_history,
|
16
|
+
'supportsFeatureImportance' => :@supports_feature_importance}
|
16
17
|
session_hash.each do |k, v|
|
17
18
|
if (k == 'links')
|
18
19
|
@links = v.map { |l| NexosisApi::Link.new(l) }
|
@@ -118,5 +119,10 @@ module NexosisApi
|
|
118
119
|
# A list of warning or error messages optionally returned from session
|
119
120
|
# @return [Array of Message]
|
120
121
|
attr_accessor :messages
|
122
|
+
|
123
|
+
# Identifies if this session will provide feature importance scores when completed
|
124
|
+
# @return [Boolean]
|
125
|
+
# @since 2.4.0
|
126
|
+
attr_reader :supports_feature_importance
|
121
127
|
end
|
122
128
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module NexosisApi
|
2
|
+
# Class to hold the parse results of an outlier response
|
3
|
+
# @note When Nexosis runs a time-series forecast, a smoothed dataset is created in addition
|
4
|
+
# to the original. These outlier values represent those which were modified in that smoothed
|
5
|
+
# dataset.
|
6
|
+
# @since 2.4.0
|
7
|
+
class TimeseriesOutliers < SessionResponse
|
8
|
+
def initialize(outlier_hash)
|
9
|
+
data = outlier_hash.fetch(:data) { |k| outlier_hash.fetch(k.to_s) }
|
10
|
+
@data = NexosisApi::PagedArray.new(outlier_hash, data.map { |v| NexosisApi::Outlier.new(v) })
|
11
|
+
super(outlier_hash.reject { |k, _v| k.to_s.casecmp('data').zero? })
|
12
|
+
end
|
13
|
+
|
14
|
+
# The set of outlier values found in the given sessions dataset
|
15
|
+
# @return [NexosisApi::PagedArray NexosisApi::Outlier]
|
16
|
+
attr_reader :data
|
17
|
+
end
|
18
|
+
end
|
data/nexosisapi.gemspec
CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.licenses = ['Apache-2.0']
|
15
15
|
spec.name = 'nexosis_api'
|
16
16
|
spec.require_paths = ['lib']
|
17
|
-
spec.required_ruby_version = '>= 2.
|
17
|
+
spec.required_ruby_version = '>= 2.3.0'
|
18
18
|
spec.summary = "Ruby client for working with the Nexosis API"
|
19
|
-
spec.version = '2.
|
19
|
+
spec.version = '2.4.0'
|
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: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nexosis,Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/nexosis_api.rb
|
49
49
|
- lib/nexosis_api/algorithm.rb
|
50
50
|
- lib/nexosis_api/algorithm_contestant.rb
|
51
|
+
- lib/nexosis_api/anomaly_distances.rb
|
51
52
|
- lib/nexosis_api/anomaly_scores.rb
|
52
53
|
- lib/nexosis_api/calendar_jointarget.rb
|
53
54
|
- lib/nexosis_api/classifier_result.rb
|
@@ -68,6 +69,8 @@ files:
|
|
68
69
|
- lib/nexosis_api/dataset_jointarget.rb
|
69
70
|
- lib/nexosis_api/dataset_model.rb
|
70
71
|
- lib/nexosis_api/dataset_summary.rb
|
72
|
+
- lib/nexosis_api/distance_metric.rb
|
73
|
+
- lib/nexosis_api/feature_importance.rb
|
71
74
|
- lib/nexosis_api/http_exception.rb
|
72
75
|
- lib/nexosis_api/impact_metric.rb
|
73
76
|
- lib/nexosis_api/imports_response.rb
|
@@ -76,6 +79,7 @@ files:
|
|
76
79
|
- lib/nexosis_api/message.rb
|
77
80
|
- lib/nexosis_api/metric.rb
|
78
81
|
- lib/nexosis_api/model_summary.rb
|
82
|
+
- lib/nexosis_api/outlier.rb
|
79
83
|
- lib/nexosis_api/paged_array.rb
|
80
84
|
- lib/nexosis_api/predict_response.rb
|
81
85
|
- lib/nexosis_api/session.rb
|
@@ -84,6 +88,7 @@ files:
|
|
84
88
|
- lib/nexosis_api/session_result.rb
|
85
89
|
- lib/nexosis_api/session_selection_metrics.rb
|
86
90
|
- lib/nexosis_api/time_interval.rb
|
91
|
+
- lib/nexosis_api/timeseries_outliers.rb
|
87
92
|
- lib/nexosis_api/view_data.rb
|
88
93
|
- lib/nexosis_api/view_definition.rb
|
89
94
|
- lib/nexosis_api/vocabulary_summary.rb
|
@@ -102,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
107
|
requirements:
|
103
108
|
- - ">="
|
104
109
|
- !ruby/object:Gem::Version
|
105
|
-
version: 2.
|
110
|
+
version: 2.3.0
|
106
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
112
|
requirements:
|
108
113
|
- - ">="
|
@@ -110,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
115
|
version: '0'
|
111
116
|
requirements: []
|
112
117
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.6
|
118
|
+
rubygems_version: 2.7.6
|
114
119
|
signing_key:
|
115
120
|
specification_version: 4
|
116
121
|
summary: Ruby client for working with the Nexosis API
|