Scoring metric(s) to evaluate. - If None (default): Uses R2 score. Returns List[float]. - If Callable: Single scoring function (e.g., mean_squared_error). Returns List[float]. - If Dict: Dictionary of {name: scoring_func}. Returns Dict[str, List[float]].
Array of stacked predictions for all targets, shape (n_samples, n_targets).
Examples
>>>import pandas as pd>>>import numpy as np>>>from spotoptim.utils.evalimport mo_eval_models
>>># Generate dummy data>>> np.random.seed(42)>>> X_train = pd.DataFrame(np.random.rand(100, 5), columns=[f'x{i}'for i inrange(5)])>>> y_train = pd.DataFrame(np.random.rand(100, 3), columns=[f'y{i}'for i inrange(3)])>>> X_test = pd.DataFrame(np.random.rand(20, 5), columns=[f'x{i}'for i inrange(5)])>>> y_test = pd.DataFrame(np.random.rand(20, 3), columns=[f'y{i}'for i inrange(3)])
>>># Example 1: Default behavior (R2 score)>>>def make_model():... from sklearn.linear_model import Ridge... return Ridge()>>> r2_scores, models, preds = mo_eval_models(X_train, y_train, X_test, y_test, make_model)Training model for target 1/3...Training model for target 2/3...Training model for target 3/3...Model scores: ['-0.10', '-0.13', '-0.19']Predictions shape: (20, 3)
>>># Example 2: Custom single score (MSE)>>>from sklearn.metrics import mean_squared_error>>> mse_scores, _, _ = mo_eval_models(X_train, y_train, X_test, y_test, make_model, scores=mean_squared_error)Training model for target 1/3...Training model for target 2/3...Training model for target 3/3...Model scores: ['0.07', '0.09', '0.10']Predictions shape: (20, 3)
>>># Example 3: Multiple custom scores>>>from sklearn.metrics import mean_absolute_error, r2_score>>> my_scores = {'R2': r2_score, 'MSE': mean_squared_error, 'MAE': mean_absolute_error}>>> all_scores, _, _ = mo_eval_models(X_train, y_train, X_test, y_test, make_model, scores=my_scores)Training model for target 1/3...Training model for target 2/3...Training model for target 3/3...Model scores: R2: ['-0.10', '-0.13', '-0.19'] MSE: ['0.07', '0.09', '0.10'] MAE: ['0.21', '0.27', '0.28']Predictions shape: (20, 3)