Files
iqa-study/scripts/nr_fusion/models.py
T
2025-04-12 03:19:13 +01:00

41 lines
1.0 KiB
Python

'''
Filename: models.py
Path: /home/netoa/Desktop/ISR/scripts/nr_fusion
Created Date: Monday March 24th 2025
Author: Andre Neto
-----
Last Modified: Mon Mar 24 2025
Modified By: Andre Neto
-----
Copyright (c) 2025 Institute of Systems and Robotics
'''
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import cross_val_predict
from sklearn.preprocessing import StandardScaler
def train_regressor(x, y):
"""
Train and cross-validate a RandomForest regressor.
Args:
X (np.ndarray): Feature matrix.
y (np.ndarray): Target values (pseudo-MOS).
Returns:
y_pred (np.ndarray): Cross-validated predictions.
model (Regressor): Trained RandomForest model.
scaler (StandardScaler): Feature normalizer.
"""
scaler = StandardScaler()
x_scaled = scaler.fit_transform(x)
model = RandomForestRegressor(n_estimators=100, random_state=42)
y_pred = cross_val_predict(model, x_scaled, y, cv=5)
model.fit(x_scaled, y)
return y_pred, model, scaler