#!/usr/bin/gawk -f BEGIN { FS = ","; # Initialize the field separator. OFS = ","; # Initialize the output field separator. PredX = 30; # Initialize the range for Pred. } { Method=$1 Est=$2 Act=$3 Count[Method]++; i=Count[Method]; Estimate[Method,i]=Est; Actual[Method,i]=Act; } END { # Calculate avg estimates and actuals for (x in Count) { for(i=1;i<=Count[x];i++) { AvgEstimate[x]+=Estimate[x,i]; AvgActual[x]+=Actual[x,i]; } AvgEstimate[x]/=Count[x]; AvgActual[x]/=Count[x]; } printf("Method,MMRE,MedianMRE,Pred%d,Correlation\n",PredX); for (x in Count) { mmre=0; pred=0; for(i=1;i<=Count[x];i++) { Corr_Se+=((Estimate[x,i]-AvgEstimate[x])*(Estimate[x,i]-AvgEstimate[x])); Corr_Sa+=((Actual[x,i]-AvgActual[x])*(Actual[x,i]-AvgActual[x])); Corr_Sea+=((Estimate[x,i]-AvgEstimate[x])*(Actual[x,i]-AvgActual[x])); re=100*((Estimate[x,i]-Actual[x,i])/Actual[x,i]); mre[i]=re<0?-1*re:re; mmre+=mre[i]; {if (mre[i]<=PredX){pred++;}} } Corr_Se/=(Count[x]-1); Corr_Sa/=(Count[x]-1); Corr_Sea/=(Count[x]-1); Corr=(Corr_Sea/sqrt(Corr_Se*Corr_Sa)); mmre/=Count[x]; pred/=Count[x]; n = asort(mre); i = int (n/2); med_mre = mre[i]; printf("%s,%.2f,%.2f,%.2f,%.3f\n",x,mmre,med_mre,pred,Corr); } }