modelabuer / py_test.py
abuer's picture
Upload py_test.py
c70edac verified
Raw History Blame Contribute Delete
1.2 kB
# ### 脚本结构介绍
# 每个脚本都主要由两个函数构成:`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))