SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import csv
  2. import sys
  3.  
  4. #This is matching script you can use locally for testing your output format
  5.  
  6. def r2_score(y_true,y_pred):
  7.  
  8.     num = 0.0
  9.     s = 0.0
  10.     for i in range(len(y_true)):
  11.         num += (y_true[i]-y_pred[i])**2
  12.         s += y_true[i]
  13.  
  14.     avg = s/len(y_true)
  15.  
  16.     denom = 0.0
  17.     for i in range(len(y_true)):
  18.         denom += (y_true[i]-avg)**2
  19.    
  20.     return 1 - num/(denom*1.0)
  21.  
  22.  
  23. def check(file1,file2):
  24.     labels_true=[]
  25.     labels_predicted=[]
  26.     with open(file1) as csv_file:
  27.         csv_reader = csv.reader(csv_file, delimiter=',')
  28.         line_count = 0
  29.         for row in csv_reader:
  30.             print(row,line_count)
  31.             if line_count != 0 and row!=[]:
  32.                 labels_true.append(float(row[1]))
  33.             line_count += 1
  34.         total_lines = line_count
  35.            
  36.     with open(file2) as csv_file:
  37.         cnt = 0
  38.         csv_reader = csv.reader(csv_file, delimiter=',')
  39.         line_count = 0
  40.         for row in csv_reader:
  41.             if line_count != 0 and row!=[]:
  42.                 labels_predicted.append(float(row[1]))
  43.             line_count += 1
  44.             #Process only the lines for which there is something in the input!
  45.             if line_count==total_lines:
  46.                 break
  47.            
  48.     return int((r2_score(labels_true,labels_predicted))*100)
  49.  
  50.  
  51. f1 = sys.argv[1] #Actual File
  52. f2 = sys.argv[2] #Predictions File
  53. print(check(f1,f2)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top