File size: 1,643 Bytes
b42b662
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f9da36
b42b662
 
 
 
 
 
 
 
 
 
 
 
4f9da36
b42b662
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import argparse
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd

from download_ixi import DEFAULT_DESTINATION


def evaluate_ixi_predictions(
    labels: str,
    predictions: str
) -> None:
    labels = pd.read_excel(labels)
    predictions = pd.read_csv(predictions)

    predictions['IXI_ID'] = predictions['source'].apply(
        lambda path: int(path.split('/')[-1][3:6])
    )
    predictions['age_prediction'] = predictions['age']
    predictions = pd.merge(
        predictions[['IXI_ID', 'age_prediction']],
        labels[['IXI_ID', 'AGE']],
        on='IXI_ID',
        how='left'
    )

    mae = np.mean(np.abs(predictions['AGE'] - predictions['age_prediction']))
    print(f'MAE: {mae:.2f}')

    plt.scatter(predictions['AGE'], predictions['age_prediction'])
    plt.xlabel('True age')
    plt.ylabel('Predicted age')
    plt.title('Age prediction')
    plt.show()


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        'Evaluates predictions for the IXI dataset'
    )
    parser.add_argument(
        '-l', '--labels',
        required=False,
        default=os.path.join(DEFAULT_DESTINATION, 'IXI.xls'),
        help='Path to XLSX containing labels'
    )
    parser.add_argument(
        '-p', '--predictions',
        required=False,
        default=os.path.join(
            DEFAULT_DESTINATION,
            'outputs',
            'predictions.csv'
        ),
        help='Path to CSV containing predictions'
    )

    args = parser.parse_args()

    evaluate_ixi_predictions(
        labels=args.labels,
        predictions=args.predictions
    )