File size: 1,039 Bytes
242c54b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import argparse

import pandas as pd
from sklearn.metrics import accuracy_score, confusion_matrix


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--ground-truth", required=True)
    parser.add_argument("--predictions", required=True)

    args = parser.parse_args()

    df_true = pd.read_csv(args.ground_truth)
    df_pred = pd.read_csv(args.predictions)

    if "label" not in df_true.columns or "label" not in df_pred.columns:
        raise ValueError("Оба файла должны содержать колонку 'label'")

    if len(df_true) != len(df_pred):
        raise ValueError(
            f"Разная длина файлов: ground-truth={len(df_true)}, "
            f"predictions={len(df_pred)}"
        )

    y_true = df_true["label"].values
    y_pred = df_pred["label"].values

    acc = accuracy_score(y_true, y_pred)
    cm = confusion_matrix(y_true, y_pred)

    print(f"Accuracy: {acc:.4f}")
    print("Confusion matrix:")
    print(cm)


if __name__ == "__main__":
    main()