Class: EasyML::Model

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Core::ModelCore
Defined in:
app/models/easy_ml/model.rb

Direct Known Subclasses

EasyML::Models::XGBoost

Instance Attribute Summary

Attributes included from Core::ModelCore

#dataset

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::ModelCore

#allowed_metrics, #cleanup, #cleanup!, #decode_labels, #evaluate, #fit, #fit?, #get_params, included, #load, #predict, #save, #save_model_file

Class Method Details

.table_ready?Boolean

Placeholder if the table doesn’t exist (keeps the file quiet)

Returns:

  • (Boolean)


10
11
12
# File 'app/models/easy_ml/model.rb', line 10

def self.table_ready?
  false
end

Instance Method Details

#mark_liveObject



35
36
37
38
39
40
# File 'app/models/easy_ml/model.rb', line 35

def mark_live
  transaction do
    self.class.where(name: name).where.not(id: id).update_all(is_live: false)
    self.class.where(id: id).update_all(is_live: true)
  end
end

#only_one_model_is_live?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/easy_ml/model.rb', line 22

def only_one_model_is_live?
  return if @marking_live

  if previous_versions.live.count > 1
    raise "Multiple previous versions of #{name} are live! This should never happen. Update previous versions to is_live=false before proceeding"
  end

  return unless previous_versions.live.any? && is_live

  errors.add(:is_live,
             "cannot mark model live when previous version is live. Explicitly use the mark_live method to mark this as the live version")
end

#previous_versionsObject



42
43
44
# File 'app/models/easy_ml/model.rb', line 42

def previous_versions
  EasyML::Model.where(name: name).order(id: :desc)
end