Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import sys
- #This is matching script you can use locally for testing your output format
- def r2_score(y_true,y_pred):
- num = 0.0
- s = 0.0
- for i in range(len(y_true)):
- num += (y_true[i]-y_pred[i])**2
- s += y_true[i]
- avg = s/len(y_true)
- denom = 0.0
- for i in range(len(y_true)):
- denom += (y_true[i]-avg)**2
- return 1 - num/(denom*1.0)
- def check(file1,file2):
- labels_true=[]
- labels_predicted=[]
- with open(file1) as csv_file:
- csv_reader = csv.reader(csv_file, delimiter=',')
- line_count = 0
- for row in csv_reader:
- print(row,line_count)
- if line_count != 0 and row!=[]:
- labels_true.append(float(row[1]))
- line_count += 1
- total_lines = line_count
- with open(file2) as csv_file:
- cnt = 0
- csv_reader = csv.reader(csv_file, delimiter=',')
- line_count = 0
- for row in csv_reader:
- if line_count != 0 and row!=[]:
- labels_predicted.append(float(row[1]))
- line_count += 1
- #Process only the lines for which there is something in the input!
- return int((r2_score(labels_true,labels_predicted))*100)
- f1 = sys.argv[1] #Actual File
- f2 = sys.argv[2] #Predictions File
- print(check(f1,f2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement