Class: AdaBoost::ContingencyTable
- Inherits:
-
Object
- Object
- AdaBoost::ContingencyTable
- Defined in:
- lib/adaboost/contingency_table.rb
Instance Method Summary collapse
- #accuracy ⇒ Object
- #add_prediction(y, h) ⇒ Object
- #class_to_index(k) ⇒ Object
- #condition_negative ⇒ Object
- #condition_positive ⇒ Object
- #diagnostic_odds_ratio ⇒ Object
- #fall_out ⇒ Object
- #false_discovery_rate ⇒ Object
- #false_negative ⇒ Object
- #false_negative_rate ⇒ Object
- #false_omission_rate ⇒ Object
- #false_positive ⇒ Object
- #false_positive_rate ⇒ Object
-
#initialize ⇒ ContingencyTable
constructor
A new instance of ContingencyTable.
- #negative_likelihood_ratio ⇒ Object
- #negative_predictive_value ⇒ Object
- #outcome_negative ⇒ Object
- #outcome_positive ⇒ Object
- #positive_likelihood_ratio ⇒ Object
- #positive_predictive_value ⇒ Object
- #precision ⇒ Object
- #predicted_condition_negative ⇒ Object
- #predicted_condition_positive ⇒ Object
- #prevalence ⇒ Object
- #recall ⇒ Object
- #sensitivity ⇒ Object
- #specificity ⇒ Object
- #to_s ⇒ Object
- #total_population ⇒ Object
- #true_negative ⇒ Object
- #true_negative_rate ⇒ Object
- #true_positive ⇒ Object
- #true_positive_rate ⇒ Object
Constructor Details
#initialize ⇒ ContingencyTable
Returns a new instance of ContingencyTable.
5 6 7 |
# File 'lib/adaboost/contingency_table.rb', line 5 def initialize @table = [[0, 0], [0, 0]] end |
Instance Method Details
#accuracy ⇒ Object
93 94 95 |
# File 'lib/adaboost/contingency_table.rb', line 93 def accuracy (true_positive + true_negative) / total_population.to_f end |
#add_prediction(y, h) ⇒ Object
25 26 27 |
# File 'lib/adaboost/contingency_table.rb', line 25 def add_prediction(y, h) @table[class_to_index(y)][class_to_index(h)] += 1 end |
#class_to_index(k) ⇒ Object
178 179 180 |
# File 'lib/adaboost/contingency_table.rb', line 178 def class_to_index(k) (k > 0) ? 1 : 0 end |
#condition_negative ⇒ Object
53 54 55 |
# File 'lib/adaboost/contingency_table.rb', line 53 def condition_negative false_positive + true_negative end |
#condition_positive ⇒ Object
49 50 51 |
# File 'lib/adaboost/contingency_table.rb', line 49 def condition_positive true_positive + false_negative end |
#diagnostic_odds_ratio ⇒ Object
125 126 127 |
# File 'lib/adaboost/contingency_table.rb', line 125 def diagnostic_odds_ratio positive_likelihood_ratio / negative_likelihood_ratio.to_f end |
#fall_out ⇒ Object
77 78 79 |
# File 'lib/adaboost/contingency_table.rb', line 77 def fall_out false_positive_rate end |
#false_discovery_rate ⇒ Object
105 106 107 |
# File 'lib/adaboost/contingency_table.rb', line 105 def false_discovery_rate false_positive / outcome_positive.to_f end |
#false_negative ⇒ Object
21 22 23 |
# File 'lib/adaboost/contingency_table.rb', line 21 def false_negative @table[1][0] end |
#false_negative_rate ⇒ Object
81 82 83 |
# File 'lib/adaboost/contingency_table.rb', line 81 def false_negative_rate false_negative / condition_positive.to_f end |
#false_omission_rate ⇒ Object
109 110 111 |
# File 'lib/adaboost/contingency_table.rb', line 109 def false_omission_rate false_negative / outcome_negative.to_f end |
#false_positive ⇒ Object
13 14 15 |
# File 'lib/adaboost/contingency_table.rb', line 13 def false_positive @table[0][1] end |
#false_positive_rate ⇒ Object
73 74 75 |
# File 'lib/adaboost/contingency_table.rb', line 73 def false_positive_rate false_positive / condition_negative.to_f end |
#negative_likelihood_ratio ⇒ Object
121 122 123 |
# File 'lib/adaboost/contingency_table.rb', line 121 def negative_likelihood_ratio false_negative_rate / true_negative_rate.to_f end |
#negative_predictive_value ⇒ Object
113 114 115 |
# File 'lib/adaboost/contingency_table.rb', line 113 def negative_predictive_value true_negative / outcome_negative.to_f end |
#outcome_negative ⇒ Object
33 34 35 |
# File 'lib/adaboost/contingency_table.rb', line 33 def outcome_negative true_negative + false_negative end |
#outcome_positive ⇒ Object
29 30 31 |
# File 'lib/adaboost/contingency_table.rb', line 29 def outcome_positive true_positive + false_positive end |
#positive_likelihood_ratio ⇒ Object
117 118 119 |
# File 'lib/adaboost/contingency_table.rb', line 117 def positive_likelihood_ratio true_positive_rate / false_positive_rate.to_f end |
#positive_predictive_value ⇒ Object
97 98 99 |
# File 'lib/adaboost/contingency_table.rb', line 97 def positive_predictive_value true_positive / outcome_positive.to_f end |
#precision ⇒ Object
101 102 103 |
# File 'lib/adaboost/contingency_table.rb', line 101 def precision positive_predictive_value end |
#predicted_condition_negative ⇒ Object
45 46 47 |
# File 'lib/adaboost/contingency_table.rb', line 45 def predicted_condition_negative false_negative + true_negative end |
#predicted_condition_positive ⇒ Object
41 42 43 |
# File 'lib/adaboost/contingency_table.rb', line 41 def predicted_condition_positive true_positive + false_positive end |
#prevalence ⇒ Object
57 58 59 |
# File 'lib/adaboost/contingency_table.rb', line 57 def prevalence condition_positive / total_population.to_f end |
#recall ⇒ Object
65 66 67 |
# File 'lib/adaboost/contingency_table.rb', line 65 def recall true_positive_rate end |
#sensitivity ⇒ Object
69 70 71 |
# File 'lib/adaboost/contingency_table.rb', line 69 def sensitivity true_positive_rate end |
#specificity ⇒ Object
89 90 91 |
# File 'lib/adaboost/contingency_table.rb', line 89 def specificity true_negative_rate end |
#to_s ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/adaboost/contingency_table.rb', line 129 def to_s "\nTotal population: %d\t \ \nCondition positive: %d\t \ \nCondition negative: %d\t \ \nPredicted Condition positive: %d\t \ \nPredicted Condition negative: %d\t \ \nTrue positive: %d\t \ \nTrue negative: %d\t \ \nFalse Negative: %d\t \ \nFalse Positive: %d\t \ \nPrevalence = Σ Condition positive / Σ Total population: %f\t \ \nTrue positive rate (TPR) = Σ True positive / Σ Condition positive: %f\t \ \nFalse positive rate (FPR) = Σ False positive / Σ Condition negative: %f\t \ \nFalse negative rate (FNR) = Σ False negative / Σ Condition positive: %f\t \ \nTrue negative rate (TNR) = Σ True negative / Σ Condition negative: %f\t \ \nAccuracy (ACC) = Σ True positive \ Σ True negative / Σ Total population: %f\t \ \nPositive predictive value (PPV) = Σ True positive / Σ Test outcome positive: %f\t \ \nFalse discovery rate (FDR) = Σ False positive / Σ Test outcome positive: %f\t \ \nFalse omission rate (FOR) = Σ False negative / Σ Test outcome negative: %f\t \ \nNegative predictive value (NPV) = Σ True negative / Σ Test outcome negative: %f\t \ \nPositive likelihood ratio (LR\) = TPR / FPR: %f\t \ \nNegative likelihood ratio (LR−) = FNR / TNR: %f\t \ \nDiagnostic odds ratio (DOR) = LR+ / LR−: %f\t" % [ total_population, condition_positive, condition_negative, predicted_condition_positive, predicted_condition_negative, true_positive, true_negative, false_negative, false_positive, prevalence, true_positive_rate, false_positive_rate, false_negative_rate, true_negative_rate, accuracy, positive_predictive_value, false_discovery_rate, false_omission_rate, negative_predictive_value, positive_likelihood_ratio, negative_likelihood_ratio, diagnostic_odds_ratio ] end |
#total_population ⇒ Object
37 38 39 |
# File 'lib/adaboost/contingency_table.rb', line 37 def total_population @table[0][0] + @table[0][1] + @table[1][0] + @table[1][1] end |
#true_negative ⇒ Object
17 18 19 |
# File 'lib/adaboost/contingency_table.rb', line 17 def true_negative @table[0][0] end |
#true_negative_rate ⇒ Object
85 86 87 |
# File 'lib/adaboost/contingency_table.rb', line 85 def true_negative_rate true_negative / condition_negative.to_f end |
#true_positive ⇒ Object
9 10 11 |
# File 'lib/adaboost/contingency_table.rb', line 9 def true_positive @table[1][1] end |
#true_positive_rate ⇒ Object
61 62 63 |
# File 'lib/adaboost/contingency_table.rb', line 61 def true_positive_rate true_positive / condition_positive.to_f end |