34 lines
935 B
Python
34 lines
935 B
Python
'''
|
|
Filename: evaluation.py
|
|
Path: /home/netoa/Desktop/ISR/scripts
|
|
Created Date: Monday March 24th 2025
|
|
Author: Andre Neto
|
|
-----
|
|
Last Modified: Tue Mar 25 2025
|
|
Modified By: Andre Neto
|
|
-----
|
|
Copyright (c) 2025 Institute of Systems and Robotics
|
|
'''
|
|
|
|
from sklearn.model_selection import cross_val_predict, KFold
|
|
from sklearn.metrics import mean_squared_error, mean_absolute_error
|
|
from scipy.stats import pearsonr, spearmanr
|
|
|
|
|
|
def evaluate_model_cv(model, x, y, cv=5):
|
|
"""Evaluate model with cross-validation and return metrics."""
|
|
kf = KFold(n_splits=cv, shuffle=True, random_state=42)
|
|
y_pred = cross_val_predict(model, x, y, cv=kf)
|
|
|
|
plcc, _ = pearsonr(y, y_pred)
|
|
srcc, _ = spearmanr(y, y_pred)
|
|
mse = mean_squared_error(y, y_pred)
|
|
mae = mean_absolute_error(y, y_pred)
|
|
|
|
return {
|
|
"PLCC": round(plcc, 4),
|
|
"SRCC": round(srcc, 4),
|
|
"MSE": round(mse, 4),
|
|
"MAE": round(mae, 4)
|
|
}
|