-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathcalculateEvaluationCCC.py
82 lines (56 loc) · 2.1 KB
/
calculateEvaluationCCC.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from __future__ import print_function
import argparse
import os
import csv
import sys
from scipy.stats import pearsonr
import numpy
import pandas
def mse(y_true, y_pred):
from sklearn.metrics import mean_squared_error
return mean_squared_error(y_true,y_pred)
def f1(y_true, y_pred):
from sklearn.metrics import f1_score
label = [0,1,2,3,4,5,6]
return f1_score(y_true,y_pred,labels=label,average="micro")
def ccc(y_true, y_pred):
true_mean = numpy.mean(y_true)
true_variance = numpy.var(y_true)
pred_mean = numpy.mean(y_pred)
pred_variance = numpy.var(y_pred)
rho,_ = pearsonr(y_pred,y_true)
std_predictions = numpy.std(y_pred)
std_gt = numpy.std(y_true)
ccc = 2 * rho * std_gt * std_predictions / (
std_predictions ** 2 + std_gt ** 2 +
(pred_mean - true_mean) ** 2)
return ccc, rho
def calculateCCC(validationFile, modelOutputFile):
dataY = pandas.read_csv(validationFile, header=0, sep=",")
dataYPred = pandas.read_csv(modelOutputFile, header=0, sep=",")
dataYArousal = dataY["arousal"]
dataYValence = dataY["valence"]
dataYPredArousal = dataYPred["arousal"]
dataYPredValence = dataYPred["valence"]
arousalCCC, acor = ccc(dataYArousal, dataYPredArousal)
arousalmse = mse(dataYArousal, dataYPredArousal)
valenceCCC, vcor = ccc(dataYValence, dataYPredValence)
valencemse = mse(dataYValence, dataYPredValence)
print ("Arousal CCC: ", arousalCCC)
print ("Arousal Pearson Cor: ", acor)
print ("Arousal MSE: ", arousalmse)
print ("Valence CCC: ", valenceCCC)
print ("Valence cor: ", vcor)
print ("Valence MSE: ", valencemse)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("validationFile")
parser.add_argument("modelOutputFile")
opt = parser.parse_args()
if not os.path.exists(opt.validationFile):
print("Cannot find validation File")
sys.exit(-1)
if not os.path.exists(opt.modelOutputFile):
print("Cannot find modelOutput File")
sys.exit(-1)
calculateCCC(opt.validationFile, opt.modelOutputFile)