summaryrefslogtreecommitdiff
path: root/scripts/confusion-matrix-summary.rb
blob: 129d69ab1244194d39a001ec535bc06f8eb7f35f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env ruby
require 'csv'
require 'yaml'

results = {}
ARGV.each do |f|
  csv = CSV.read(f,headers: false,:col_sep => ",")
  tp = csv[0][0].to_f
  fp = csv[0][1].to_f
  fn = csv[1][0].to_f
  tn = csv[1][1].to_f

  result = {
    :tp => tp.to_i,
    :fp => fp.to_i,
    :tn => tn.to_i,
    :fn => fn.to_i,
    :n => (tp+fp+tn+fn).to_i,
    :acc => ((tp+tn)/(tp+fp+tn+fn)).round(2),
    :tpr => (tp/(tp+fn)).round(2),
    :fpr => (fp/(fp+tn)).round(2),
    :tnr => (tn/(tn+fp)).round(2),
    :ppv => (tp/(tp+fp)).round(2),
    :npv => (tn/(tn+fn)).round(2),
    :acc_perc => (100*(tp+tn)/(tp+fp+tn+fn)).round(0),
    :tpr_perc => (100*tp/(tp+fn)).round(0),
    :tnr_perc => (100*tn/(tn+fp)).round(0),
    :ppv_perc => (100*tp/(tp+fp)).round(0),
    :npv_perc => (100*tn/(tn+fn)).round(0),
  }
  results[File.basename(f,".csv")] = result
end

puts results.to_yaml