class AdaBoost::ContingencyTable

Public Class Methods

new() click to toggle source
# File lib/adaboost/contingency_table.rb, line 5
def initialize
  @table = [[0, 0], [0, 0]]
end

Public Instance Methods

accuracy() click to toggle source
# File lib/adaboost/contingency_table.rb, line 93
def accuracy
  (true_positive + true_negative) / total_population.to_f
end
add_prediction(y, h) click to toggle source
# 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) click to toggle source
# File lib/adaboost/contingency_table.rb, line 178
def class_to_index(k)
  (k > 0) ? 1 : 0
end
condition_negative() click to toggle source
# File lib/adaboost/contingency_table.rb, line 53
def condition_negative
  false_positive + true_negative
end
condition_positive() click to toggle source
# File lib/adaboost/contingency_table.rb, line 49
def condition_positive
  true_positive + false_negative
end
diagnostic_odds_ratio() click to toggle source
# File lib/adaboost/contingency_table.rb, line 125
def diagnostic_odds_ratio
  positive_likelihood_ratio / negative_likelihood_ratio.to_f
end
fall_out() click to toggle source
# File lib/adaboost/contingency_table.rb, line 77
def fall_out
  false_positive_rate
end
false_discovery_rate() click to toggle source
# File lib/adaboost/contingency_table.rb, line 105
def false_discovery_rate
  false_positive / outcome_positive.to_f
end
false_negative() click to toggle source
# File lib/adaboost/contingency_table.rb, line 21
def false_negative
  @table[1][0]
end
false_negative_rate() click to toggle source
# File lib/adaboost/contingency_table.rb, line 81
def false_negative_rate
  false_negative / condition_positive.to_f
end
false_omission_rate() click to toggle source
# File lib/adaboost/contingency_table.rb, line 109
def false_omission_rate
  false_negative / outcome_negative.to_f
end
false_positive() click to toggle source
# File lib/adaboost/contingency_table.rb, line 13
def false_positive
  @table[0][1]
end
false_positive_rate() click to toggle source
# File lib/adaboost/contingency_table.rb, line 73
def false_positive_rate
  false_positive / condition_negative.to_f
end
negative_likelihood_ratio() click to toggle source
# File lib/adaboost/contingency_table.rb, line 121
def negative_likelihood_ratio
  false_negative_rate / true_negative_rate.to_f
end
negative_predictive_value() click to toggle source
# File lib/adaboost/contingency_table.rb, line 113
def negative_predictive_value
  true_negative / outcome_negative.to_f
end
outcome_negative() click to toggle source
# File lib/adaboost/contingency_table.rb, line 33
def outcome_negative
  true_negative + false_negative
end
outcome_positive() click to toggle source
# File lib/adaboost/contingency_table.rb, line 29
def outcome_positive
  true_positive + false_positive
end
positive_likelihood_ratio() click to toggle source
# File lib/adaboost/contingency_table.rb, line 117
def positive_likelihood_ratio
  true_positive_rate / false_positive_rate.to_f
end
positive_predictive_value() click to toggle source
# File lib/adaboost/contingency_table.rb, line 97
def positive_predictive_value
  true_positive / outcome_positive.to_f
end
precision() click to toggle source
# File lib/adaboost/contingency_table.rb, line 101
def precision
  positive_predictive_value
end
predicted_condition_negative() click to toggle source
# File lib/adaboost/contingency_table.rb, line 45
def predicted_condition_negative
  false_negative + true_negative
end
predicted_condition_positive() click to toggle source
# File lib/adaboost/contingency_table.rb, line 41
def predicted_condition_positive
  true_positive + false_positive
end
prevalence() click to toggle source
# File lib/adaboost/contingency_table.rb, line 57
def prevalence
  condition_positive / total_population.to_f
end
recall() click to toggle source
# File lib/adaboost/contingency_table.rb, line 65
def recall
  true_positive_rate
end
sensitivity() click to toggle source
# File lib/adaboost/contingency_table.rb, line 69
def sensitivity
  true_positive_rate
end
specificity() click to toggle source
# File lib/adaboost/contingency_table.rb, line 89
def specificity
  true_negative_rate
end
to_s() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/adaboost/contingency_table.rb, line 17
def true_negative
  @table[0][0]
end
true_negative_rate() click to toggle source
# File lib/adaboost/contingency_table.rb, line 85
def true_negative_rate
  true_negative / condition_negative.to_f
end
true_positive() click to toggle source
# File lib/adaboost/contingency_table.rb, line 9
def true_positive
  @table[1][1]
end
true_positive_rate() click to toggle source
# File lib/adaboost/contingency_table.rb, line 61
def true_positive_rate
  true_positive / condition_positive.to_f
end