nexosis_api 1.4.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nexosis_api/algorithm_contestant.rb +43 -0
- data/lib/nexosis_api/client.rb +19 -9
- data/lib/nexosis_api/client/contest.rb +66 -0
- data/lib/nexosis_api/client/imports.rb +73 -13
- data/lib/nexosis_api/client/sessions.rb +6 -33
- data/lib/nexosis_api/imports_response.rb +1 -1
- data/lib/nexosis_api/metric.rb +3 -8
- data/lib/nexosis_api/model_summary.rb +1 -1
- data/lib/nexosis_api/session.rb +12 -37
- data/lib/nexosis_api/session_contest.rb +30 -0
- data/lib/nexosis_api/session_response.rb +20 -15
- data/lib/nexosis_api/session_result.rb +1 -1
- data/lib/nexosis_api/session_selection_metrics.rb +21 -0
- data/nexosisapi.gemspec +1 -1
- metadata +6 -4
- data/lib/nexosis_api/algorithm_run.rb +0 -32
- data/lib/nexosis_api/algorithm_selection.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98e972055cf506f2a4e54483c50f57605ade5992
|
4
|
+
data.tar.gz: f9da5b974d540d66e589c8f09a5df16a10ff9d81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f763f8f98fd480d8d84e2b77ace7d8097f426ff003fc1e5bb01ad114306792ab589ef147e297e7a1684ef1ebec5e602f45c5daf5c3f9a1204ab6f78b07452bc
|
7
|
+
data.tar.gz: ea5d25a7bc0502c59ac958c26af5d170e80a0ee6fa5389e395a61fed7e1e2b1cbccd6c209c44fb0b70420233156167c0b37f7497f4e272450d0f25f869d5dbd2
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module NexosisApi
|
2
|
+
# Class to parse results of an algorithm run
|
3
|
+
# @since 2.0.0
|
4
|
+
class AlgorithmContestant
|
5
|
+
def initialize(contestant_hash)
|
6
|
+
contestant_hash.each do |k, v|
|
7
|
+
if k.to_s == 'links'
|
8
|
+
instance_variable_set("@#{k}", v.map { |l| NexosisApi::Link.new(l) unless l.nil? })
|
9
|
+
elsif k.to_s == 'dataSourceProperties'
|
10
|
+
@datasource_properties = v
|
11
|
+
elsif k.to_s == 'algorithm'
|
12
|
+
instance_variable_set("@#{k}", NexosisApi::Algorithm.new(v)) unless v.nil?
|
13
|
+
else
|
14
|
+
instance_variable_set("@#{k}", v)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Unique identifier for this contestant
|
20
|
+
attr_reader :id
|
21
|
+
|
22
|
+
# Identifier of algorithm run
|
23
|
+
# @return [NexosisApi::Algorithm]
|
24
|
+
attr_accessor :algorithm
|
25
|
+
|
26
|
+
# Name and value for metrics calculated for this algorithm
|
27
|
+
# @return [Hash]
|
28
|
+
attr_accessor :metrics
|
29
|
+
|
30
|
+
# Relevant hypermedia as {NexosisApi::Link}
|
31
|
+
# @return [Array]
|
32
|
+
attr_accessor :links
|
33
|
+
|
34
|
+
# Operations performed on datasource prior to run
|
35
|
+
# @return [Array]
|
36
|
+
attr_reader :datasource_properties
|
37
|
+
|
38
|
+
# The test dataset used to score the algo
|
39
|
+
# @return [Array of Hash] columnname: value hash of each observation row in test set
|
40
|
+
# @note - may be nil when reviewing contestant lists
|
41
|
+
attr_reader :data
|
42
|
+
end
|
43
|
+
end
|
data/lib/nexosis_api/client.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require 'nexosis_api/
|
2
|
-
require 'nexosis_api/algorithm_selection'
|
1
|
+
require 'nexosis_api/algorithm_contestant'
|
3
2
|
require 'nexosis_api/algorithm'
|
4
3
|
require 'nexosis_api/calendar_jointarget'
|
5
4
|
require 'nexosis_api/classifier_result'
|
@@ -21,12 +20,15 @@ require 'nexosis_api/metric'
|
|
21
20
|
require 'nexosis_api/model_summary'
|
22
21
|
require 'nexosis_api/paged_array'
|
23
22
|
require 'nexosis_api/predict_response'
|
23
|
+
require 'nexosis_api/session_contest'
|
24
24
|
require 'nexosis_api/session_response'
|
25
25
|
require 'nexosis_api/session_result'
|
26
|
+
require 'nexosis_api/session_selection_metrics'
|
26
27
|
require 'nexosis_api/session'
|
27
28
|
require 'nexosis_api/time_interval'
|
28
29
|
require 'nexosis_api/view_definition'
|
29
30
|
require 'nexosis_api/view_data'
|
31
|
+
require 'nexosis_api/client/contest'
|
30
32
|
require 'nexosis_api/client/sessions'
|
31
33
|
require 'nexosis_api/client/datasets'
|
32
34
|
require 'nexosis_api/client/imports'
|
@@ -43,6 +45,7 @@ module NexosisApi
|
|
43
45
|
include Client::Imports
|
44
46
|
include Client::Views
|
45
47
|
include Client::Models
|
48
|
+
include Client::Contest
|
46
49
|
|
47
50
|
def initialize(options = {})
|
48
51
|
raise ArgumentError, 'api_key was not defined' unless options[:api_key].nil? == false
|
@@ -53,15 +56,22 @@ module NexosisApi
|
|
53
56
|
@options = { headers: @headers, format: :json }
|
54
57
|
end
|
55
58
|
|
56
|
-
# Gets the
|
59
|
+
# Gets the quota stats for the account
|
57
60
|
#
|
58
|
-
# @return [
|
59
|
-
|
60
|
-
|
61
|
-
def get_account_balance()
|
62
|
-
session_url = '/sessions'
|
61
|
+
# @return [Hash] a hash of quota values and current values
|
62
|
+
def get_account_quotas()
|
63
|
+
session_url = '/sessions?page=0&pageSize=1'
|
63
64
|
response = self.class.get(session_url, @options)
|
64
|
-
response.headers
|
65
|
+
response.headers.select { |k, _v| k.to_s.start_with? 'nexosis-account' }
|
66
|
+
end
|
67
|
+
|
68
|
+
# Provide access to read or modify the api key
|
69
|
+
# @return [String]
|
70
|
+
# @since 2.0.0
|
71
|
+
def api_key(value)
|
72
|
+
@api_key = value unless value.nil?
|
73
|
+
@headers['api-key'] = @api_key
|
74
|
+
@api_key
|
65
75
|
end
|
66
76
|
|
67
77
|
private
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module NexosisApi
|
2
|
+
class Client
|
3
|
+
# Session Contest-based API operations
|
4
|
+
#
|
5
|
+
# @see http://docs.nexosis.com/
|
6
|
+
# @since 2.0.0
|
7
|
+
module Contest
|
8
|
+
|
9
|
+
# @return [NexosisApi::SessionContest]
|
10
|
+
def get_session_contest(session_id)
|
11
|
+
raise ArgumentError, 'session_id was not provided and is not optional ' if session_id.to_s.empty?
|
12
|
+
contest_url = "/sessions/#{session_id}/contest"
|
13
|
+
response = self.class.get(contest_url, headers: @headers)
|
14
|
+
raise HttpException.new("There was a problem getting session contest #{response.code}.",
|
15
|
+
"getting contest for #{session_id}",
|
16
|
+
response) unless response.success?
|
17
|
+
NexosisApi::SessionContest.new(response.parsed_response)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [NexosisApi::AlgorithmContestant]
|
21
|
+
def get_contest_champion(session_id)
|
22
|
+
raise ArgumentError, 'session_id was not provided and is not optional ' if session_id.to_s.empty?
|
23
|
+
champion_url = "/sessions/#{session_id}/contest/champion"
|
24
|
+
response = self.class.get(champion_url, headers: @headers)
|
25
|
+
raise HttpException.new("There was a problem getting session champion #{response.code}.",
|
26
|
+
"getting champion for #{session_id}",
|
27
|
+
response) unless response.success?
|
28
|
+
NexosisApi::AlgorithmContestant.new(response.parsed_response)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Array of NexosisApi::AlgorithmContestant]
|
32
|
+
def get_contestants(session_id)
|
33
|
+
raise ArgumentError, 'session_id was not provided and is not optional ' if session_id.to_s.empty?
|
34
|
+
contestants_url = "/sessions/#{session_id}/contest/contestants"
|
35
|
+
response = self.class.get(contestants_url, headers: @headers)
|
36
|
+
raise HttpException.new("There was a problem getting session contestants #{response.code}.",
|
37
|
+
"getting contestants for #{session_id}",
|
38
|
+
response) unless response.success?
|
39
|
+
response.parsed_response['items'].map { |c| NexosisApi::AlgorithmContestant.new(c) }
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [NexosisApi::AlgorithmContestant]
|
43
|
+
def get_contestant_results(session_id, contestant_id)
|
44
|
+
raise ArgumentError, 'session_id was not provided and is not optional ' if session_id.to_s.empty?
|
45
|
+
raise ArgumentError, 'contestant_id was not provided and is not optional ' if contestant_id.to_s.empty?
|
46
|
+
contestant_url = "/sessions/#{session_id}/contest/contestants/#{contestant_id}"
|
47
|
+
response = self.class.get(contestant_url, headers: @headers)
|
48
|
+
raise HttpException.new("There was a problem getting session contestant result #{response.code}.",
|
49
|
+
"getting contestant result for #{session_id}:#{contestant_id}",
|
50
|
+
response) unless response.success?
|
51
|
+
NexosisApi::AlgorithmContestant.new(response.parsed_response)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [NexosisApi::SessionSelectionMetrics]
|
55
|
+
def get_selection_metrics(session_id)
|
56
|
+
raise ArgumentError, 'session_id was not provided and is not optional ' if session_id.to_s.empty?
|
57
|
+
selection_url = "/sessions/#{session_id}/contest/selection"
|
58
|
+
response = self.class.get(selection_url, headers: @headers)
|
59
|
+
raise HttpException.new("There was a problem getting session selection metrics #{response.code}.",
|
60
|
+
"getting selection metrics for #{session_id}",
|
61
|
+
response) unless response.success?
|
62
|
+
NexosisApi::SessionSelectionMetrics.new(response.parsed_response)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -36,10 +36,12 @@ module NexosisApi
|
|
36
36
|
# @param bucket_name [String] the AWS S3 bucket name in which the path will be found
|
37
37
|
# @param path [String] the path within the bucket (usually file name)
|
38
38
|
# @param region [String] the region in which your bucket exists. Defaults to us-east-1
|
39
|
+
# @param credentials [Hash] :access_key_id and :secret_access_key for user with rights to read the target file.
|
39
40
|
# @param column_metadata [Array of NexosisApi::Column] description of each column in target dataset. Optional.
|
40
41
|
# @return [NexosisApi::ImportsResponse]
|
41
42
|
# @see http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region for information on region names
|
42
|
-
|
43
|
+
# @note If credentials are provided they will be encrypted at the server, used once, and then removed from storage.
|
44
|
+
def import_from_s3(dataset_name, bucket_name, path, region = 'us-east-1', credentials = {}, column_metadata = [])
|
43
45
|
raise ArgumentError, 'dataset_name was not provided and is not optional ' unless dataset_name.to_s.empty? == false
|
44
46
|
raise ArgumentError, 'bucket_name was not provided and is not optional ' unless bucket_name.to_s.empty? == false
|
45
47
|
raise ArgumentError, 'path was not provided and is not optional ' unless path.to_s.empty? == false
|
@@ -52,29 +54,87 @@ module NexosisApi
|
|
52
54
|
'region' => region,
|
53
55
|
'columns' => column_json
|
54
56
|
}
|
57
|
+
body['accessKeyId'] = credentials[:access_key_id] unless credentials.nil? || credentials[:access_key_id].nil?
|
58
|
+
body['secretAccessKey'] = credentials[:secret_access_key] unless credentials.nil? || credentials[:secret_access_key].nil?
|
55
59
|
response = self.class.post(s3_import_url, headers: @headers, body: body.to_json)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
60
|
+
raise HttpException.new("There was a problem importing from s3: #{response.code}.",
|
61
|
+
"uploading dataset from s3 #{dataset_name}",
|
62
|
+
response) unless response.success?
|
63
|
+
NexosisApi::ImportsResponse.new(response.parsed_response)
|
61
64
|
end
|
62
65
|
|
63
|
-
# Get
|
66
|
+
# Get response back from import created previously. Presumably to check status.
|
64
67
|
#
|
65
68
|
# @param import_id [String] The id returned from a previous request to import
|
66
69
|
# @return [NexosisApi::ImportsResponse]
|
67
|
-
# @example get
|
70
|
+
# @example get import
|
68
71
|
# NexosisApi.client.retrieve_import('740dca2a-b488-4322-887e-fa473b1caa54')
|
69
72
|
def retrieve_import(import_id)
|
70
73
|
raise ArgumentError, 'import_id was not provided and is not optional ' unless import_id.to_s.empty? == false
|
71
74
|
imports_url = "/imports/#{import_id}"
|
72
75
|
response = self.class.get(imports_url, headers: @headers)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
raise HttpException.new("There was a problem getting the import #{response.code}.",
|
77
|
+
"requesting an import #{import_id}", response) unless response.success?
|
78
|
+
NexosisApi::ImportsResponse.new(response.parsed_response)
|
79
|
+
end
|
80
|
+
|
81
|
+
# Import a csv, json file (gzip'd or raw) from a Microsoft Azure storage blob
|
82
|
+
#
|
83
|
+
# @param dataset_name [String] the name to give to the new dataset or existing dataset to which this data will be upserted
|
84
|
+
# @param connection_string [String] the azure blob storage connection string providing access to the file resource
|
85
|
+
# @param container [String] the container in which the object is located.
|
86
|
+
# @param blob_name [String] the name of the object to import, usually a file. Always csv or json content.
|
87
|
+
# If folders have been used this will contain the full path within the container.
|
88
|
+
# @param column_metadata [Array of NexosisApi::Column] description of each column in target dataset. Optional.
|
89
|
+
# @return [NexosisApi::ImportsResponse]
|
90
|
+
# @since 2.0.0
|
91
|
+
# @note the connection string provided will be encrypted at the server, used once, and then removed from storage.
|
92
|
+
def import_from_azure(dataset_name, connection_string, container, blob_name, column_metadata = [])
|
93
|
+
raise ArgumentError, 'dataset_name was not provided and is not optional ' unless dataset_name.empty? == false
|
94
|
+
raise ArgumentError, 'connection_string was not provided and is not optional ' unless connection_string.empty? == false
|
95
|
+
raise ArgumentError, 'container was not provided and is not optional ' unless container.empty? == false
|
96
|
+
raise ArgumentError, 'blob_name was not provided and is not optional ' unless blob_name.empty? == false
|
97
|
+
azure_url = '/imports/azure'
|
98
|
+
column_json = Column.to_json(column_metadata)
|
99
|
+
body = {
|
100
|
+
'dataSetName' => dataset_name,
|
101
|
+
'connectionString' => connection_string,
|
102
|
+
'container' => container,
|
103
|
+
'blob' => blob_name,
|
104
|
+
'columns' => column_json
|
105
|
+
}
|
106
|
+
response = self.class.post(azure_url, headers: @headers, body: body.to_json)
|
107
|
+
raise HttpException.new("There was a problem importing from azure: #{response.code}.",
|
108
|
+
"uploading dataset from azure #{dataset_name}",
|
109
|
+
response) unless response.success?
|
110
|
+
NexosisApi::ImportsResponse.new(response.parsed_response)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Import a csv or json file directly from any avaiable and reachable public endpoint.
|
114
|
+
#
|
115
|
+
# @param dataset_name [String] the name to give to the new dataset or existing dataset to which this data will be upserted
|
116
|
+
# @param url [String] the url indicating where to find the file resource to import
|
117
|
+
# @param column_metadata [Array of NexosisApi::Column] description of each column in target dataset. Optional.
|
118
|
+
# @param options [Hash] may provide basic auth credentials or a 'content-type' value to identify csv or json content.
|
119
|
+
# @return [NexosisApi::ImportsResponse]
|
120
|
+
# @note imports depend on file extensions, so use a content type indicator if json or csv cannot be inferred.
|
121
|
+
# @note Urls protected by basic auth can be accessed if given a userid and password in options
|
122
|
+
# @since 2.0.0
|
123
|
+
def import_from_url(dataset_name, url, column_metadata = [], options = {})
|
124
|
+
raise ArgumentError, 'dataset_name was not provided and is not optional ' unless dataset_name.empty? == false
|
125
|
+
raise ArgumentError, 'url was not provided and is not optional ' unless url.empty? == false
|
126
|
+
endpoint_url = '/imports/url'
|
127
|
+
column_json = Column.to_json(column_metadata)
|
128
|
+
body = {
|
129
|
+
'dataSetName' => dataset_name,
|
130
|
+
'url' => url,
|
131
|
+
'columns' => column_json
|
132
|
+
}
|
133
|
+
response = self.class.post(endpoint_url, headers: @headers, body: body.to_json)
|
134
|
+
raise HttpException.new("There was a problem importing from url: #{response.code}.",
|
135
|
+
"uploading dataset from #{url}",
|
136
|
+
response) unless response.success?
|
137
|
+
NexosisApi::ImportsResponse.new(response.parsed_response)
|
78
138
|
end
|
79
139
|
end
|
80
140
|
end
|
@@ -78,19 +78,7 @@ module NexosisApi
|
|
78
78
|
# For instance if your data includes many recoreds per hour, then you could request hour, day, or any other result interval.
|
79
79
|
# 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.
|
80
80
|
def create_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil)
|
81
|
-
create_session(dataset_name, start_date, end_date, target_column,
|
82
|
-
end
|
83
|
-
|
84
|
-
# Estimate the cost of a forecast from data already saved to the API.
|
85
|
-
#
|
86
|
-
# @param dataset_name [String] The name of the saved data set that has the data to forecast on.
|
87
|
-
# @param start_date [DateTime] The starting date of the forecast period. Can be ISO 8601 string.
|
88
|
-
# @param end_date [DateTime] The ending date of the forecast period. Can be ISO 8601 string.
|
89
|
-
# @param target_column [String] The name of the column for which you want predictions. Nil if defined in dataset.
|
90
|
-
# @param result_interval [NexosisApi::TimeInterval] (optional) - The date/time interval (e.g. Day, Hour) at which predictions should be generated. So, if Hour is specified for this parameter you will get a Result record for each hour between startDate and endDate. If unspecified, we’ll generate predictions at a Day interval.
|
91
|
-
# @return [NexosisApi::SessionResponse] providing information about the sesssion, including the cost
|
92
|
-
def estimate_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY)
|
93
|
-
create_session(dataset_name, start_date, end_date, target_column, true, nil, 'forecast', result_interval)
|
81
|
+
create_session(dataset_name, start_date, end_date, target_column, nil, 'forecast', result_interval, column_metadata)
|
94
82
|
end
|
95
83
|
|
96
84
|
# Analyze impact for an event with data already saved to the API.
|
@@ -104,20 +92,7 @@ module NexosisApi
|
|
104
92
|
# @param column_metadata [Array of NexosisApi::Column] (optional) - specification for how to handle columns if different from existing metadata on dataset
|
105
93
|
# @return [NexosisApi::SessionResponse] providing information about the sesssion
|
106
94
|
def create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil)
|
107
|
-
create_session(dataset_name, start_date, end_date, target_column,
|
108
|
-
end
|
109
|
-
|
110
|
-
# Estimate the cost of impact analysis for an event with data already saved to the API.
|
111
|
-
#
|
112
|
-
# @param dataset_name [String] The name of the saved data set that has the data to forecast on.
|
113
|
-
# @param start_date [DateTime] The starting date of the impactful event. Can be ISO 8601 string.
|
114
|
-
# @param end_date [DateTime] The ending date of the impactful event. Can be ISO 8601 string.
|
115
|
-
# @param event_name [String] The name of the event.
|
116
|
-
# @param target_column [String] The name of the column for which you want predictions. Nil if defined in dataset.
|
117
|
-
# @param result_interval [NexosisApi::TimeInterval] (optional) - The date/time interval (e.g. Day, Hour) at which predictions should be generated. So, if Hour is specified for this parameter you will get a Result record for each hour between startDate and endDate. If unspecified, we’ll generate predictions at a Day interval.
|
118
|
-
# @return [NexosisApi::SessionResponse] providing information about the sesssion, including the cost
|
119
|
-
def estimate_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY)
|
120
|
-
create_session(dataset_name, start_date, end_date, target_column, true, event_name, 'impact', result_interval)
|
95
|
+
create_session(dataset_name, start_date, end_date, target_column, event_name, 'impact', result_interval, column_metadata)
|
121
96
|
end
|
122
97
|
|
123
98
|
# Get the results of the session.
|
@@ -157,7 +132,7 @@ module NexosisApi
|
|
157
132
|
# @param datasource_name [String] The datasource from which to build the model
|
158
133
|
# @param target_column [String] The column which will be predicted when using the model
|
159
134
|
# @param columns [Hash] column metadata to modify roles, imputation, or target.
|
160
|
-
# @param options [Hash] prediction_domain and or
|
135
|
+
# @param options [Hash] prediction_domain and or balance (true or false) indicator for classification
|
161
136
|
# @note - classifcation assumes balanced classes. The use of a 'balanced=false' option
|
162
137
|
# indicates that no attempt should be made to sample the classes in balanced fashion.
|
163
138
|
# @since 1.3.0
|
@@ -166,10 +141,9 @@ module NexosisApi
|
|
166
141
|
body = {
|
167
142
|
dataSourceName: datasource_name,
|
168
143
|
targetColumn: target_column,
|
169
|
-
predictionDomain: options[:prediction_domain].downcase
|
170
|
-
isEstimate: false
|
144
|
+
predictionDomain: options[:prediction_domain].downcase
|
171
145
|
}
|
172
|
-
body.store(:
|
146
|
+
body.store(:extraParameters, { balance: options[:balance] }) if options.include?(:balance) && body[:predictionDomain] == 'classification'
|
173
147
|
body.store(columns: columns) unless columns.empty?
|
174
148
|
response = self.class.post(model_url, headers: @headers, body: body.to_json)
|
175
149
|
if response.success?
|
@@ -195,13 +169,12 @@ module NexosisApi
|
|
195
169
|
private
|
196
170
|
|
197
171
|
# @private
|
198
|
-
def create_session(dataset_name, start_date, end_date, target_column = nil,
|
172
|
+
def create_session(dataset_name, start_date, end_date, target_column = nil, event_name = nil, type = 'forecast', result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil)
|
199
173
|
session_url = "/sessions/#{type}"
|
200
174
|
query = {
|
201
175
|
'targetColumn' => target_column.to_s,
|
202
176
|
'startDate' => start_date.to_s,
|
203
177
|
'endDate' => end_date.to_s,
|
204
|
-
'isestimate' => is_estimate.to_s,
|
205
178
|
'resultInterval' => result_interval.to_s
|
206
179
|
}
|
207
180
|
query['dataSetName'] = dataset_name.to_s unless dataset_name.to_s.empty?
|
data/lib/nexosis_api/metric.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
module NexosisApi
|
2
2
|
# Class to parse algorithm metrics from model results
|
3
3
|
class Metric
|
4
|
-
def initialize(
|
5
|
-
|
6
|
-
|
7
|
-
end
|
4
|
+
def initialize(name, value)
|
5
|
+
@name = name
|
6
|
+
@value = value
|
8
7
|
end
|
9
8
|
|
10
9
|
# Friendly name of the metric
|
11
10
|
# @return [String]
|
12
11
|
attr_accessor :name
|
13
12
|
|
14
|
-
# Identifier for metric type
|
15
|
-
# @return [String]
|
16
|
-
attr_accessor :code
|
17
|
-
|
18
13
|
# Calculated metric
|
19
14
|
# @return [Float]
|
20
15
|
attr_accessor :value
|
@@ -23,7 +23,7 @@ module NexosisApi
|
|
23
23
|
elsif (k == 'metrics')
|
24
24
|
@metrics = v.reject { |_key, value| value.nil? }
|
25
25
|
.map do |col_key, col_val|
|
26
|
-
NexosisApi::Metric.new(
|
26
|
+
NexosisApi::Metric.new(col_key, col_val)
|
27
27
|
end
|
28
28
|
elsif (k == 'sessionId')
|
29
29
|
@session_id = v
|
data/lib/nexosis_api/session.rb
CHANGED
@@ -9,7 +9,10 @@ module NexosisApi
|
|
9
9
|
'availablePredictionIntervals' => :@prediction_intervals,
|
10
10
|
'startDate' => :@start_date,
|
11
11
|
'endDate' => :@end_date,
|
12
|
-
'predictionDomain' => :@prediction_domain
|
12
|
+
'predictionDomain' => :@prediction_domain,
|
13
|
+
'extraParameters' => :@extra_parameters,
|
14
|
+
'targetColumn' => :@target_column,
|
15
|
+
'statusHistory' => :@status_history }
|
13
16
|
session_hash.each do |k, v|
|
14
17
|
if (k == 'links')
|
15
18
|
@links = v.map { |l| NexosisApi::Link.new(l) }
|
@@ -25,15 +28,10 @@ module NexosisApi
|
|
25
28
|
else
|
26
29
|
instance_variable_set("@#{k}", v) unless v.nil?
|
27
30
|
end
|
28
|
-
instance_variable_set(val_map[k], v) unless val_map[k].nil?
|
31
|
+
instance_variable_set(val_map[k.to_s], v) unless val_map[k.to_s].nil?
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
32
|
-
# identifier for this sesssion
|
33
|
-
# @return [String]
|
34
|
-
# @deprecated use session_id instead
|
35
|
-
attr_accessor :sessionId
|
36
|
-
|
37
35
|
# identifier for this sesssion
|
38
36
|
# @return [String]
|
39
37
|
# @since 1.4.0
|
@@ -43,36 +41,23 @@ module NexosisApi
|
|
43
41
|
# @return [String]
|
44
42
|
attr_accessor :type
|
45
43
|
|
46
|
-
# Is this session requested,
|
44
|
+
# Is this session requested, started, or completed
|
47
45
|
# @return [String]
|
48
46
|
attr_accessor :status
|
49
47
|
|
50
48
|
# Date and status of each status this session has entered
|
51
|
-
# @return [Hash]
|
52
|
-
|
49
|
+
# @return [Array of Hash]
|
50
|
+
# @note - each status object in array is form { date: 'date', status: 'status' }
|
51
|
+
attr_accessor :status_history
|
53
52
|
|
54
53
|
# reserved for future extensions
|
55
54
|
# @return [Hash]
|
56
|
-
|
57
|
-
|
58
|
-
# the dataset used in this session
|
59
|
-
# @return [String]
|
60
|
-
# @deprecated - Use the @datasource_name property instead
|
61
|
-
attr_accessor :dataSetName
|
55
|
+
# @note - included 'balance' parameter for classification models
|
56
|
+
attr_accessor :extra_parameters
|
62
57
|
|
63
58
|
# The column in the dataset for which this session ran predictions
|
64
59
|
# @return [String]
|
65
|
-
attr_accessor :
|
66
|
-
|
67
|
-
# The start date of analysis in this session
|
68
|
-
# @return [DateTime]
|
69
|
-
# @deprecated use start_date instead
|
70
|
-
attr_accessor :startDate
|
71
|
-
|
72
|
-
# The end date of analysis in this session
|
73
|
-
# @return [DateTime]
|
74
|
-
# @deprecated use end_date instead
|
75
|
-
attr_accessor :endDate
|
60
|
+
attr_accessor :target_column
|
76
61
|
|
77
62
|
# The start date of analysis in this session
|
78
63
|
# @return [DateTime]
|
@@ -88,10 +73,6 @@ module NexosisApi
|
|
88
73
|
# @return [Array of NexosisApi::Link]
|
89
74
|
attr_accessor :links
|
90
75
|
|
91
|
-
# Is this session an estimate only session
|
92
|
-
# @return [Boolean]
|
93
|
-
attr_accessor :is_estimate
|
94
|
-
|
95
76
|
# The column descriptors for the data in this session
|
96
77
|
# will reflect either the metadata sent in, defaults form dataset, or inferred values
|
97
78
|
# @return[Array of NexosisApi::Column]
|
@@ -133,11 +114,5 @@ module NexosisApi
|
|
133
114
|
# A list of warning or error messages optionally returned from session
|
134
115
|
# @return [Array of Message]
|
135
116
|
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
|
142
117
|
end
|
143
118
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module NexosisApi
|
2
|
+
# Class to parse the algorithm contestants from a session
|
3
|
+
# @since 2.0.0
|
4
|
+
class SessionContest < Session
|
5
|
+
def initialize(contest_hash)
|
6
|
+
contest_hash.each do |k, v|
|
7
|
+
if k.to_s == 'champion'
|
8
|
+
instance_variable_set("@#{k}", NexosisApi::AlgorithmContestant.new(v))
|
9
|
+
elsif k.to_s == 'contestants'
|
10
|
+
instance_variable_set("@#{k}", v.map { |c| NexosisApi::AlgorithmContestant.new(c) })
|
11
|
+
elsif k.to_s == 'championMetric'
|
12
|
+
@champion_metric = v
|
13
|
+
end
|
14
|
+
end
|
15
|
+
super(contest_hash.reject { |key, _v| key == 'champion' || key == 'contestants' })
|
16
|
+
end
|
17
|
+
|
18
|
+
# The champion algorithm used
|
19
|
+
# @return [NexosisApi::AlgorithmContestant]
|
20
|
+
attr_accessor :champion
|
21
|
+
|
22
|
+
# All other algorithms which competed
|
23
|
+
# @return [Array of NexosisApi::AlgorithmContestant]
|
24
|
+
attr_accessor :contestants
|
25
|
+
|
26
|
+
# Name of metric used to determine champion algorithm
|
27
|
+
# @return [String] metric name
|
28
|
+
attr_accessor :champion_metric
|
29
|
+
end
|
30
|
+
end
|
@@ -1,28 +1,33 @@
|
|
1
1
|
require 'nexosis_api/session'
|
2
2
|
|
3
3
|
module NexosisApi
|
4
|
-
#Class to parse the results from a new session
|
4
|
+
# Class to parse the results from a new session
|
5
5
|
class SessionResponse < Session
|
6
6
|
def initialize(forecast_hash)
|
7
|
+
val_map = {
|
8
|
+
'Nexosis-Account-DataSetCount-Allotted' => :@datasets_allotted,
|
9
|
+
'Nexosis-Account-DataSetCount-Current' => :@datasets_current,
|
10
|
+
'Nexosis-Account-PredictionCount-Allotted' => :@predictions_allotted,
|
11
|
+
'Nexosis-Account-PredictionCount-Current' => :@predictions_current,
|
12
|
+
'Nexosis-Account-SessionCount-Allotted' => :@sessions_allotted,
|
13
|
+
'Nexosis-Account-SessionCount-Current' => :@sessions_current
|
14
|
+
}
|
7
15
|
forecast_hash.each do |k, v|
|
8
|
-
if(k == 'session')
|
16
|
+
if (k == 'session')
|
9
17
|
super(v) unless v.nil?
|
10
|
-
|
11
|
-
instance_variable_set(
|
12
|
-
elsif(k == 'nexosis-account-balance')
|
13
|
-
instance_variable_set('@account_balance', v[0]) unless v.nil?
|
14
|
-
elsif(k == 'balance')
|
15
|
-
@balance = v
|
18
|
+
else
|
19
|
+
instance_variable_set(val_map[k], v) unless val_map[k].nil?
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
attr_reader :datasets_allotted
|
25
|
+
attr_reader :datasets_allotted
|
26
|
+
attr_reader :datasets_current
|
27
|
+
attr_reader :predictions_allotted
|
28
|
+
attr_reader :predictions_current
|
29
|
+
attr_reader :sessions_allotted
|
30
|
+
attr_reader :sessions_current
|
31
|
+
|
27
32
|
end
|
28
33
|
end
|
@@ -6,7 +6,7 @@ module NexosisApi
|
|
6
6
|
if k.to_s == 'metrics' && session_hash['type'] == 'impact'
|
7
7
|
instance_variable_set("@#{k}", NexosisApi::ImpactMetric.new(v)) unless v.nil?
|
8
8
|
elsif k.to_s == 'metrics'
|
9
|
-
@metrics = v.map { |key, value| NexosisApi::Metric.new(
|
9
|
+
@metrics = v.map { |key, value| NexosisApi::Metric.new(key.to_s, value) } unless v.nil?
|
10
10
|
elsif k.to_s == 'data'
|
11
11
|
@data = v
|
12
12
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module NexosisApi
|
2
|
+
# Class to parse the session selection metrics from a particular session
|
3
|
+
# @since 2.0.0
|
4
|
+
class SessionSelectionMetrics < Session
|
5
|
+
def initialize(metrics_hash)
|
6
|
+
if !metrics_hash['metricSets'].nil?
|
7
|
+
@dataset_properties = metrics_hash['metricSets'][0]['dataSetProperties'] unless metrics_hash['metricSets'][0]['dataSetProperties'].nil?
|
8
|
+
@metrics = metrics_hash['metricSets'][0]['metrics'] unless metrics_hash['metricSets'][0]['metrics'].nil?
|
9
|
+
end
|
10
|
+
super(metrics_hash.reject { |k, _v| k == 'metricSets' })
|
11
|
+
end
|
12
|
+
|
13
|
+
# transformations performed on dataset prior to algorithm run
|
14
|
+
# @return [Array] string list of transformations
|
15
|
+
attr_reader :dataset_properties
|
16
|
+
|
17
|
+
# dataset metrics describing some properties of it
|
18
|
+
# @return [Hash] name value pairs of dataset metrics
|
19
|
+
attr_reader :metrics
|
20
|
+
end
|
21
|
+
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 = '
|
19
|
+
spec.version = '2.0.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:
|
4
|
+
version: 2.0.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: 2017-
|
11
|
+
date: 2017-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -47,11 +47,11 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- lib/nexosis_api.rb
|
49
49
|
- lib/nexosis_api/algorithm.rb
|
50
|
-
- lib/nexosis_api/
|
51
|
-
- lib/nexosis_api/algorithm_selection.rb
|
50
|
+
- lib/nexosis_api/algorithm_contestant.rb
|
52
51
|
- lib/nexosis_api/calendar_jointarget.rb
|
53
52
|
- lib/nexosis_api/classifier_result.rb
|
54
53
|
- lib/nexosis_api/client.rb
|
54
|
+
- lib/nexosis_api/client/contest.rb
|
55
55
|
- lib/nexosis_api/client/datasets.rb
|
56
56
|
- lib/nexosis_api/client/imports.rb
|
57
57
|
- lib/nexosis_api/client/models.rb
|
@@ -76,8 +76,10 @@ files:
|
|
76
76
|
- lib/nexosis_api/paged_array.rb
|
77
77
|
- lib/nexosis_api/predict_response.rb
|
78
78
|
- lib/nexosis_api/session.rb
|
79
|
+
- lib/nexosis_api/session_contest.rb
|
79
80
|
- lib/nexosis_api/session_response.rb
|
80
81
|
- lib/nexosis_api/session_result.rb
|
82
|
+
- lib/nexosis_api/session_selection_metrics.rb
|
81
83
|
- lib/nexosis_api/time_interval.rb
|
82
84
|
- lib/nexosis_api/view_data.rb
|
83
85
|
- lib/nexosis_api/view_definition.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module NexosisApi
|
2
|
-
# Class to parse results of an algorithm run
|
3
|
-
class AlgorithmRun
|
4
|
-
def initialize(run_hash)
|
5
|
-
run_hash.each do |k, v|
|
6
|
-
if k == 'metrics'
|
7
|
-
metric_set = []
|
8
|
-
v.each { |m| metric_set << NexosisApi::Metric.new(m) unless m.nil? }
|
9
|
-
instance_variable_set("@#{k}", metric_set)
|
10
|
-
elsif k == 'links'
|
11
|
-
link_set = []
|
12
|
-
v.each { |l| link_set << NexosisApi::Link.new(l) unless l.nil? }
|
13
|
-
instance_variable_set("@#{k}", link_set)
|
14
|
-
else
|
15
|
-
instance_variable_set("@#{k}", NexosisApi::Algorithm.new(v)) unless v.nil?
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# Identifier of algorithm run
|
21
|
-
# @return [NexosisApi::Algorithm]
|
22
|
-
attr_accessor :algorithm
|
23
|
-
|
24
|
-
# Set of {NexosisApi::Metric} on algorithm
|
25
|
-
# @return [Array]
|
26
|
-
attr_accessor :metrics
|
27
|
-
|
28
|
-
# Relevant hypermedia as {NexosisApi::Link}
|
29
|
-
# @return [Array]
|
30
|
-
attr_accessor :links
|
31
|
-
end
|
32
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module NexosisApi
|
2
|
-
# Class to parse the model data results from a session
|
3
|
-
class AlgorithmSelection
|
4
|
-
def initialize(data_hash)
|
5
|
-
data_hash.each do |k, v|
|
6
|
-
if k == 'champion'
|
7
|
-
instance_variable_set("@#{k}", NexosisApi::AlgorithmRun.new(v))
|
8
|
-
elsif k == 'contestants'
|
9
|
-
contestant_array = []
|
10
|
-
v.each { |c| contestant_array << NexosisApi::AlgorithmRun.new(c) }
|
11
|
-
instance_variable_set("@#{k}", contestant_array)
|
12
|
-
else
|
13
|
-
instance_variable_set("@#{k}", v) unless v.nil?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# The date on which this algo was selected as champion
|
19
|
-
# @return [DateTime]
|
20
|
-
attr_accessor :date
|
21
|
-
|
22
|
-
# The session which selected the algorithm
|
23
|
-
# @return [String] session identifier
|
24
|
-
attr_accessor :sessionId
|
25
|
-
|
26
|
-
# The champion algorithm used
|
27
|
-
# @return [NexosisApi::AlgorithmRun]
|
28
|
-
attr_accessor :champion
|
29
|
-
|
30
|
-
# All other algorithms which competed
|
31
|
-
# @return [Array of NexosisApi::AlgorithmRun]
|
32
|
-
attr_accessor :contestants
|
33
|
-
end
|
34
|
-
end
|