Initial clean commit

This commit is contained in:
Andre Neto
2025-04-12 03:19:13 +01:00
commit 62ff4d6c25
96 changed files with 104109 additions and 0 deletions
View File
+33
View File
@@ -0,0 +1,33 @@
'''
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)
}
+60
View File
@@ -0,0 +1,60 @@
'''
Filename: models.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.linear_model import LinearRegression, Ridge
from sklearn.ensemble import RandomForestRegressor
from sklearn.svm import SVR
def get_models():
"""Return dictionary of regression models for fusion pipeline."""
models = {
"LinearRegression": LinearRegression(),
"Ridge": Ridge(alpha=1.0),
"RandomForest": RandomForestRegressor(n_estimators=200, max_depth=None, random_state=42),
"SVR": SVR(kernel="rbf")
}
# Optional: XGBoost
try:
from xgboost import XGBRegressor
models["XGBoost"] = XGBRegressor(
n_estimators=200,
max_depth=None,
learning_rate=0.05,
reg_alpha=0.1,
reg_lambda=0.1,
subsample=0.8,
colsample_bytree=0.8,
random_state=42
)
except ImportError:
pass
# Optional: LightGBM
try:
from lightgbm import LGBMRegressor
models["LightGBM"] = LGBMRegressor(
n_estimators=200,
max_depth=None,
learning_rate=0.05,
reg_alpha=0.1,
reg_lambda=0.1,
subsample=0.8,
colsample_bytree=0.8,
random_state=42
)
except ImportError:
pass
return models
+37
View File
@@ -0,0 +1,37 @@
'''
Filename: plotting.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
'''
import os
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
def plot_fusion_result(y_true, y_pred, model_name, output_dir):
"""Scatter plot: MOS vs predicted fused score."""
os.makedirs(output_dir, exist_ok=True)
plt.figure(figsize=(6, 6))
sns.scatterplot(x=y_pred, y=y_true, alpha=0.6, color="blue")
z = np.polyfit(y_pred, y_true, 1)
p = np.poly1d(z)
plt.plot(y_pred, p(y_pred), color="red", linewidth=2)
plt.xlabel("Predicted Fused Score")
plt.ylabel("MOS")
plt.title(f"MOS vs Predicted ({model_name})")
plt.grid(True, linestyle="--", alpha=0.5)
plt.tight_layout()
plt.savefig(os.path.join(output_dir, f"fusion_plot_{model_name}.png"), dpi=300)
plt.savefig(os.path.join(output_dir, f"fusion_plot_{model_name}.eps"), dpi=300)
plt.close()
+20
View File
@@ -0,0 +1,20 @@
'''
Filename: utils.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
'''
import os
import pandas as pd
def save_fused_scores(predictions, filenames, output_path):
"""Save fused quality scores with associated filenames to CSV."""
os.makedirs(os.path.dirname(output_path), exist_ok=True)
df = pd.DataFrame({"file_name": filenames, "fused_score": predictions})
df.to_csv(output_path, index=False)