diff options
Diffstat (limited to 'bin/classification-summary.rb')
-rwxr-xr-x | bin/classification-summary.rb | 70 |
1 files changed, 68 insertions, 2 deletions
diff --git a/bin/classification-summary.rb b/bin/classification-summary.rb index a3e4172..c6755a1 100755 --- a/bin/classification-summary.rb +++ b/bin/classification-summary.rb @@ -1,4 +1,70 @@ #!/usr/bin/env ruby require_relative "../lib/lazar" -stat = ClassificationStatistics.new ARGV[0] -stat.summary +#stat = ClassificationStatistics.new ARGV[0] +#stat.summary +dir = File.join(File.dirname(ARGV[0]),"crossvalidation") +folds = Dir[File.join(dir,"[0-9]*")] + +predictions = [] +tp=0 +tn=0 +fp=0 +fn=0 +n=0 +experimental = {} + +lines = File.readlines(File.join(ARGV[0])) +lines.shift +lines.each do |line| + items = line.chomp.split(',') + experimental[items[0]] ||= [] + experimental[items[0]] << items[1].to_i +end + +File.open(File.join(dir,"predictions.csv"),"w+") do |f| + folds.each do |fold| + pred = File.readlines(File.join(fold,"test-prediction.csv")).collect{|row| row.chomp.split(",")} + pred.shift + pred.each do |prediction| + smi = prediction[0] + exp = experimental[smi] + unless exp.nil? or prediction[2].empty? or exp.empty? + p = prediction[2].to_i + n+=1 + v = "NA" + exp.each do |e| + if p and e + if p == 1 and e == 1 + v = "TP" + tp+=1 + elsif p == 0 and e == 0 + v = "TN" + tn+=1 + elsif p == 1 and e == 0 + v = "FP" + fp+=1 + elsif p == 0 and e == 1 + v = "FN" + fn+=1 + end + end + predictions << v + end + f.puts([smi,v].join(",")) + end + end + end +end + +File.open(File.join(dir,"confusion-matrix.csv"),"w+") do |f| + f.puts "#{tp},#{fp}\n#{fn},#{tn}" +end + +File.open(File.join(dir,"summary.csv"),"w+") do |f| + f.puts "accuracy,#{(tp+tn)/(tp+fp+tn+fn).to_f}" + f.puts "true_positive_rate,#{tp/(tp+fn).to_f}" + f.puts "true_negative_rate,#{tn/(tn+fp).to_f}" + f.puts "positive_predictive_value,#{tp/(tp+fp).to_f}" + f.puts "negative_predictive_value,#{tn/(tn+fn).to_f}" +end + |