noranisa commited on
Commit
fe8b2b5
·
verified ·
1 Parent(s): 63e9ea1

Create evaluation.py

Browse files
Files changed (1) hide show
  1. services/evaluation.py +24 -0
services/evaluation.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from sklearn.metrics import classification_report, accuracy_score
3
+
4
+ def evaluate_model(predict_func):
5
+ try:
6
+ df = pd.read_csv("data/eval_dataset.csv")
7
+
8
+ texts = df["text"].astype(str).tolist()
9
+ y_true = df["label"].str.capitalize().tolist()
10
+
11
+ y_pred = predict_func(texts)
12
+
13
+ report = classification_report(y_true, y_pred, output_dict=True)
14
+ acc = accuracy_score(y_true, y_pred)
15
+
16
+ return {
17
+ "accuracy": round(acc, 3),
18
+ "report": report
19
+ }
20
+
21
+ except Exception as e:
22
+ return {
23
+ "error": str(e)
24
+ }