class Datarobot::AiApi::LearningSession

Attributes

created_at[R]
dataset_id[R]
evaluation[R]
id[R]
name[R]
target[R]

Public Class Methods

all(limit: 50, offset: 0) click to toggle source

Retrieves all learning sessions as a paginated resource.

@param [Integer] limit Number of learning sessions per page @param [Integer] offset How many learning sessions to skip before this page

@return [Datarobot::AiApi::Page(Datarobot::AiApi::LearningSession)]

# 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:) click to toggle source

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

@param [String] dataset_id The ID of the dataset to learn on @param [String] target Name of the target feature @return [Datarobot::AiApi::LearningSession]

# 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) click to toggle source

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

@param [String] id The ID of the learning session to delete

@return [nil]

# 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) { |data| ... } click to toggle source

Retrieves a leanring sessoin given an ID.

@param [String] id The ID of the learning session to retrieve

@return [Datarobot::AiApi::LearningSession]

# 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
new(options = {}) click to toggle source

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

# 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

Public Instance Methods

deployment() click to toggle source

Gets the deployment for the learning session @return Datarobot::AiApi::Deployment

# 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
features() click to toggle source

gets all feature metadata for learned features of the associated dataset

@return [Array]

# 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 = {}) click to toggle source

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

@param [Hash] options A parsed response body @return [void]

# 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