Class: Datarobot::AiApi::LearningSession

Inherits:
Object
  • Object
show all
Includes:
Refreshable
Defined in:
lib/datarobot/ai_api/learning_session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Refreshable

#refresh, #refresh!

Constructor Details

#initialize(options = {}) ⇒ LearningSession

Given a parsed response body from the API, will create a new leanring sessoin object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/datarobot/ai_api/learning_session.rb', line 62

def initialize(options = {})
  # Suppresses warnings about uninitialized variables
  @id = nil
  @name = nil
  @dataset_id = nil
  @target = nil
  @created_at = nil

  set_from_options(options)
  @features = nil
  @deployment = nil
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



5
6
7
# File 'lib/datarobot/ai_api/learning_session.rb', line 5

def created_at
  @created_at
end

#dataset_idObject (readonly)

Returns the value of attribute dataset_id.



5
6
7
# File 'lib/datarobot/ai_api/learning_session.rb', line 5

def dataset_id
  @dataset_id
end

#evaluationObject (readonly)

Returns the value of attribute evaluation.



5
6
7
# File 'lib/datarobot/ai_api/learning_session.rb', line 5

def evaluation
  @evaluation
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/datarobot/ai_api/learning_session.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/datarobot/ai_api/learning_session.rb', line 5

def name
  @name
end

#targetObject (readonly)

Returns the value of attribute target.



5
6
7
# File 'lib/datarobot/ai_api/learning_session.rb', line 5

def target
  @target
end

Class Method Details

.all(limit: 50, offset: 0) ⇒ Datarobot::AiApi::Page(Datarobot::AiApi::LearningSession)

Retrieves all learning sessions as a paginated resource.

Parameters:

  • limit (Integer) (defaults to: 50)

    Number of learning sessions per page

  • offset (Integer) (defaults to: 0)

    How many learning sessions to skip before this page

Returns:



13
14
15
16
17
# File 'lib/datarobot/ai_api/learning_session.rb', line 13

def self.all(limit: 50, offset: 0)
  Datarobot::AiApi.request_endpoint('/aiapi/learningSessions/', params: {limit: limit, offset: offset}) do |data|
    Datarobot::AiApi::Page.new(self, data)
  end
end

.create(dataset_id:, target:) ⇒ Datarobot::AiApi::LearningSession

Creates a new learning session on the given target for a given dataset

Parameters:

  • dataset_id (String)

    The ID of the dataset to learn on

  • target (String)

    Name of the target feature

Returns:



40
41
42
43
44
45
46
47
48
49
# File 'lib/datarobot/ai_api/learning_session.rb', line 40

def self.create(dataset_id:, target:)
  raise "Need both dataset_id and target" unless dataset_id && target

  name ||= "Learning #{target}"
  Datarobot::AiApi.request_endpoint('/aiapi/learningSessions/', method: 'post', body: { datasetId: dataset_id, target: target }) do |data|
    task_data = Datarobot::AiApi.get(data["links"]["result"])
    task = Datarobot::AiApi::Task.new(task_data)
    task.wait_until_complete
  end
end

.delete(id) ⇒ nil

Deletes a learning session. Returns ‘nil` if the action was successful. Will raise an error if the action was unsuccessful

Parameters:

  • id (String)

    The ID of the learning session to delete

Returns:

  • (nil)


57
58
59
# File 'lib/datarobot/ai_api/learning_session.rb', line 57

def self.delete(id)
  Datarobot::AiApi.request_endpoint("/aiapi/learningSessions/#{id}", method: "delete")
end

.find(id, &block) ⇒ Datarobot::AiApi::LearningSession

Retrieves a leanring sessoin given an ID.

Parameters:

  • id (String)

    The ID of the learning session to retrieve

Returns:

Raises:



24
25
26
27
28
29
30
31
32
33
# File 'lib/datarobot/ai_api/learning_session.rb', line 24

def self.find(id, &block)
  raise Datarobot::AiApi::NotFoundError, "Cannot find LearningSession with id: nil" if id.nil?
  Datarobot::AiApi.request_endpoint("/aiapi/learningSessions/#{id}") do |data|
    if block_given?
      yield data
    else
      self.new(data)
    end
  end
end

Instance Method Details

#deploymentObject

Gets the deployment for the learning session

Returns:

  • Datarobot::AiApi::Deployment



105
106
107
108
109
# File 'lib/datarobot/ai_api/learning_session.rb', line 105

def deployment
  Datarobot::AiApi.request_endpoint("/aiapi/learningSessions/#{id}/deployment") do |data|
    @deployment = Datarobot::AiApi::Deployment.new(data)
  end
end

#featuresArray

gets all feature metadata for learned features of the associated dataset

Returns:

  • (Array)


96
97
98
99
100
101
# File 'lib/datarobot/ai_api/learning_session.rb', line 96

def features
  Datarobot::AiApi.request_endpoint("/aiapi/learningSessions/#{id}/features/") do |data|
    data = data.collect{|k,v| [k.to_s, v]}.to_h
    @features = data["features"]
  end
end

#set_from_options(options = {}) ⇒ void

This method returns an undefined value.

Takes a response body from the API. Will set all learning session attributes from the response body

Parameters:

  • options (Hash) (defaults to: {})

    A parsed response body



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/datarobot/ai_api/learning_session.rb', line 80

def set_from_options(options = {})
  # one-liner replacement for `stringify_keys`
  options = options.collect{|k,v| [k.to_s, v]}.to_h

  @name = options.dig("name") || @name
  @id = options.dig("id") || @id
  @created_at = options.dig("created") || @created_at
  @dataset_id = options.dig("datasetId") || @dataset_id
  @target = options.dig("target") || @target
  @evaluation = Datarobot::AiApi::Evaluation.new(options.dig("evaluation") || {})
end