Spaces:
Paused
Paused
Download services/evaluation.py from noranisa/Sentimen-Analysis: direct link, hf CLI and curl.
- Browser
- Download file 619 Bytes
-
https://huggingface.co/spaces/noranisa/Sentimen-Analysis/resolve/main/services/evaluation.py
- Command line
-
hf download hf://spaces/noranisa/Sentimen-Analysis/services/evaluation.py
-
curl -L -o evaluation.py https://huggingface.co/spaces/noranisa/Sentimen-Analysis/resolve/main/services/evaluation.py
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) | |
| } |