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

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

Instance Method Details

#mark_liveObject



26
27
28
29
30
31
# File 'app/models/easy_ml/model.rb', line 26

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)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/easy_ml/model.rb', line 13

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



33
34
35
# File 'app/models/easy_ml/model.rb', line 33

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