Simon Lousky 1 month ago
parent
commit
566dde378c
4 changed files with 62 additions and 0 deletions
  1. 40
    0
      code/eval.py
  2. 12
    0
      dvc.lock
  3. 9
    0
      dvc.yaml
  4. 1
    0
      metrics/eval.json

+ 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()
+

+ 12
- 0
dvc.lock

@@ -26,3 +26,15 @@ training:
     md5: d72417286b48ba89f02d83ca3f9642d4
   - path: metrics/train_metric.json
     md5: 27598e27b215ebb84ec027f92fc1b0ca
+eval:
+  cmd: python code/eval.py
+  deps:
+  - path: code/eval.py
+    md5: 75c6e9b5ffa5ab5bbf83b7c3e8de188d
+  - path: data/model.pkl
+    md5: d72417286b48ba89f02d83ca3f9642d4
+  - path: data/processed_test_data.npy
+    md5: a5257a91e73920bdd4cafd0f88105b74
+  outs:
+  - path: metrics/eval.json
+    md5: 42e05a4d1c5f16b21c304c269178b5a8

+ 9
- 0
dvc.yaml

@@ -19,3 +19,12 @@ stages:
     metrics:
     - metrics/train_metric.json:
         cache: false
+  eval:
+    cmd: python code/eval.py
+    deps:
+    - code/eval.py
+    - data/model.pkl
+    - data/processed_test_data.npy
+    metrics:
+    - metrics/eval.json:
+        cache: false

+ 1
- 0
metrics/eval.json

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