Last active
August 19, 2017 17:00
-
-
Save Zoldin/9eef13632d0a9039fe9b0dba376516a4 to your computer and use it in GitHub Desktop.
Evaluation_python_model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import precision_recall_curve | |
import sys | |
import sklearn.metrics as metrics | |
from scipy import sparse | |
from numpy import loadtxt | |
try: import cPickle as pickle # python2 | |
except: import pickle # python3 | |
import feather as ft | |
if len(sys.argv) != 4: | |
sys.stderr.write('Arguments error. Usage:\n') | |
sys.stderr.write('\tpython metrics.py MODEL_FILE TEST_MATRIX METRICS_FILE\n') | |
sys.exit(1) | |
model_file = sys.argv[1] | |
test_matrix_file = sys.argv[2] | |
metrics_file = sys.argv[3] | |
with open(model_file, 'rb') as fd: | |
model = pickle.load(fd) | |
df = ft.read_dataframe(test_matrix_file) | |
labels = df.loc[:,'label'] | |
x = df.loc[:, df.columns != 'label'] | |
predictions_by_class = model.predict_proba(x) | |
predictions = predictions_by_class[:,1] | |
precision, recall, thresholds = precision_recall_curve(labels.ix[:,0], predictions) | |
auc = metrics.auc(recall, precision) | |
#print('AUC={}'.format(metrics.auc(recall, precision))) | |
with open(metrics_file, 'w') as fd: | |
fd.write('AUC: {:4f}\n'.format(auc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment