vlad-winter 1 month ago
parent
commit
896e2a8130
4 changed files with 62 additions and 1 deletions
  1. 18 0
      Dvcfile
  2. 40 0
      code/eval.py
  3. 1 0
      metrics/eval.json
  4. 3 1
      training.dvc

+ 18 - 0
Dvcfile

@@ -0,0 +1,18 @@
+md5: f5ec7dd1a77ff91c4d01c63113f5a10b
+cmd: python code/eval.py
+wdir: .
+deps:
+- md5: a5257a91e73920bdd4cafd0f88105b74
+  path: data/processed_test_data.npy
+- md5: 2723303d5317424e48c3b404c29c387c
+  path: data/model.pkl
+- md5: 75c6e9b5ffa5ab5bbf83b7c3e8de188d
+  path: code/eval.py
+outs:
+- md5: 42e05a4d1c5f16b21c304c269178b5a8
+  path: metrics/eval.json
+  cache: false
+  metric:
+    type: json
+    xpath: accuracy
+  persist: false

+ 40 - 0
code/eval.py

@@ -0,0 +1,40 @@
+"""
+Evaluate model performance
+"""
+import pickle
+import json
+import numpy as np
+from sklearn.metrics import accuracy_score, precision_score, recall_score, roc_auc_score
+
+
+def eval_model():
+    # Load test data
+    print("Loading data and model...")
+    test_data = np.load('./data/processed_test_data.npy')
+
+    # Load trained model
+    with open('./data/model.pkl', 'rb') as f:
+        model = pickle.load(f)
+    print("done.")
+    # Divide loaded data-set into data and labels
+    labels = test_data[:, 0]
+    data = test_data[:, 1:]
+
+    # Run model on test data
+    print("Running model on test data...")
+    predictions = model.predict(data)
+    print("done.")
+
+    # Calculate metric scores
+    print("Calculating metrics...")
+    metrics = {'accuracy': accuracy_score(labels, predictions)}
+
+    # Save metrics to json file
+    with open('./metrics/eval.json', 'w') as f:
+        json.dump(metrics, f)
+    print("done.")
+
+
+if __name__ == '__main__':
+    eval_model()
+

+ 1 - 0
metrics/eval.json

@@ -0,0 +1 @@
+{"accuracy": 0.8583}

+ 3 - 1
training.dvc

@@ -15,5 +15,7 @@ outs:
 - md5: e5867e3138d0e181dbe318abd32886c3
   path: metrics/train_metric.json
   cache: false
-  metric: true
+  metric:
+    type: json
+    xpath: training_time
   persist: false