File size: 1,198 Bytes
c70edac | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # ### 脚本结构介绍
# 每个脚本都主要由两个函数构成:`validate`函数和`score`函数。
import sys
import pandas as pd
import numpy as np
from sklearn.metrics import roc_curve,auc
def validate(submit_file, test_file, options=True):
submission = pd.read_csv(submit_file,sep =',',dtype={'Prediction':str})
ground_truth = pd.read_csv(test_file,sep=',')
#### duplicate ID
if len(np.unique(submission['ID'])) != len(submission['ID']) :
raise Exception('Duplicate ID in answer File!')
#### ID not matched (the length of the ID column of the two files should be the same)
if len(np.intersect1d(submission['ID'],ground_truth['ID'])) != len(ground_truth['ID']):
raise Exception('ID column of two files not matched!')
#### prediction should be decimal
var = submission['Prediction'].apply(lambda x : x.isdigit()).any()
if var == True:
raise Exception('Prediction column only accepts float number!')
return {
'code':0,
'message':'validation success'
}
if __name__ == '__main__':
submit_file = sys.argv[1]
test_file = sys.argv[2]
print(validate(submit_file, test_file,options=True)) |