Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  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. if line_count != 0:
  31. labels_true.append(float(row[1]))
  32. line_count += 1
  33. if line_count==401:
  34. break
  35. total_lines = line_count
  36.  
  37. with open(file2) as csv_file:
  38. cnt = 0
  39. csv_reader = csv.reader(csv_file, delimiter=',')
  40. line_count = 0
  41. for row in csv_reader:
  42. if line_count != 0:
  43. labels_predicted.append(float(row[1]))
  44. line_count += 1
  45. #Process only the lines for which there is something in the input!
  46. if line_count==401:
  47. break
  48.  
  49. return int((r2_score(labels_true,labels_predicted))*100)
  50.  
  51.  
  52. f1 = sys.argv[1] #Actual File
  53. f2 = sys.argv[2] #Predictions File
  54. print(check(f1,f2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement