Sentimen-Analysis / services /evaluation.py
noranisa's picture
Create evaluation.py
fe8b2b5 verified
raw
history blame contribute delete
619 Bytes
import pandas as pd
from sklearn.metrics import classification_report, accuracy_score
def evaluate_model(predict_func):
try:
df = pd.read_csv("data/eval_dataset.csv")
texts = df["text"].astype(str).tolist()
y_true = df["label"].str.capitalize().tolist()
y_pred = predict_func(texts)
report = classification_report(y_true, y_pred, output_dict=True)
acc = accuracy_score(y_true, y_pred)
return {
"accuracy": round(acc, 3),
"report": report
}
except Exception as e:
return {
"error": str(e)
}