Class: Ossert::Classifiers::DecisionTree
- Inherits:
-
Object
- Object
- Ossert::Classifiers::DecisionTree
- Defined in:
- lib/ossert/classifiers/decision_tree.rb
Constant Summary collapse
- GRADES =
%w( ClassA ClassB ClassC ClassD ClassE ).freeze
- SECTION_DATA =
{ agility_total: ->(project) { project.agility.total.metric_values }, agility_last_year: ->(project) { project.agility.quarters.last_year_data }, community_total: ->(project) { project.community.total.metric_values }, community_last_year: ->(project) { project.community.quarters.last_year_data } }.freeze
- SECTION_METRICS =
{ agility_total: Stats::AgilityTotal.metrics, agility_last_year: Stats::AgilityQuarter.metrics, community_total: Stats::CommunityTotal.metrics, community_last_year: Stats::CommunityQuarter.metrics }.freeze
Class Attribute Summary collapse
-
.all ⇒ Object
Returns the value of attribute all.
Instance Attribute Summary collapse
-
#agility_last_year_dec_tree ⇒ Object
readonly
Returns the value of attribute agility_last_year_dec_tree.
-
#agility_total_dec_tree ⇒ Object
readonly
Returns the value of attribute agility_total_dec_tree.
-
#community_last_year_dec_tree ⇒ Object
readonly
Returns the value of attribute community_last_year_dec_tree.
-
#community_total_dec_tree ⇒ Object
readonly
Returns the value of attribute community_total_dec_tree.
-
#train_group ⇒ Object
readonly
Returns the value of attribute train_group.
Class Method Summary collapse
Instance Method Summary collapse
- #check(project) ⇒ Object
-
#initialize(train_group) ⇒ DecisionTree
constructor
A new instance of DecisionTree.
- #initialize_data ⇒ Object
- #ready? ⇒ Boolean
- #train ⇒ Object
Constructor Details
#initialize(train_group) ⇒ DecisionTree
Returns a new instance of DecisionTree.
28 29 30 31 32 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 28 def initialize(train_group) @train_group = train_group (self.class.all ||= []) << self end |
Class Attribute Details
.all ⇒ Object
Returns the value of attribute all.
17 18 19 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 17 def all @all end |
Instance Attribute Details
#agility_last_year_dec_tree ⇒ Object (readonly)
Returns the value of attribute agility_last_year_dec_tree.
35 36 37 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 35 def agility_last_year_dec_tree @agility_last_year_dec_tree end |
#agility_total_dec_tree ⇒ Object (readonly)
Returns the value of attribute agility_total_dec_tree.
35 36 37 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 35 def agility_total_dec_tree @agility_total_dec_tree end |
#community_last_year_dec_tree ⇒ Object (readonly)
Returns the value of attribute community_last_year_dec_tree.
35 36 37 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 35 def community_last_year_dec_tree @community_last_year_dec_tree end |
#community_total_dec_tree ⇒ Object (readonly)
Returns the value of attribute community_total_dec_tree.
35 36 37 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 35 def community_total_dec_tree @community_total_dec_tree end |
#train_group ⇒ Object (readonly)
Returns the value of attribute train_group.
34 35 36 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 34 def train_group @train_group end |
Class Method Details
.current ⇒ Object
23 24 25 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 23 def current all.last end |
.for_current_projects ⇒ Object
19 20 21 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 19 def for_current_projects new(Project.projects_by_reference) end |
Instance Method Details
#check(project) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 41 def check(project) { agility: { total: agility_total_check(project), last_year: agility_last_year_check(project) }, community: { total: community_total_check(project), last_year: community_last_year_check(project) } } end |
#initialize_data ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 97 def initialize_data result = { agility_total: [], agility_last_year: [], community_total: [], community_last_year: [] } GRADES.each_with_object(train_group) do |grade, grouped_projects| grouped_projects[grade].each do |project| SECTION_DATA.each do |section, data_collector| result[section] << (data_collector.call(project) << grade) end end end result end |
#ready? ⇒ Boolean
77 78 79 80 81 82 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 77 def ready? agility_total_dec_tree.presence && agility_last_year_dec_tree.presence && community_total_dec_tree.presence && community_last_year_dec_tree.presence end |
#train ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ossert/classifiers/decision_tree.rb', line 84 def train data = initialize_data trees = SECTION_METRICS.map do |section, metrics| ::DecisionTree::ID3Tree.new(metrics, data[section], 'ClassE', :continuous) end.tap(&:train) @agility_total_dec_tree, @agility_last_year_dec_tree, @community_total_dec_tree, @community_last_year_dec_tree = trees end |