Browse Source

Evaluate basic SVM model

Eli Simhayev 3 months ago
parent
commit
f948bceec7
3 changed files with 57 additions and 0 deletions
  1. 16 0
      Dvcfile
  2. 40 0
      code/eval.py
  3. 1 0
      metrics/eval.json

+ 16 - 0
Dvcfile

@@ -0,0 +1,16 @@
+md5: 1ed5eb1e7c1bdd23ba8672218030eb91
+cmd: python code/eval.py
+wdir: .
+deps:
+- md5: a5257a91e73920bdd4cafd0f88105b74
+  path: data/processed_test_data.npy
+- md5: c48258ba79feb691b5600a2001411485
+  path: data/model.pkl
+- md5: 75c6e9b5ffa5ab5bbf83b7c3e8de188d
+  path: code/eval.py
+outs:
+- md5: 42e05a4d1c5f16b21c304c269178b5a8
+  path: metrics/eval.json
+  cache: false
+  metric: true
+  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}