flexcv.metrics
This module implements the MetricsDict class and it's default metrics. It is used to specify which metrics to calculate in the outer loop of the cross-validation.
flexcv.metrics.MetricsDict
Bases: dict
A dictionary that maps metric names to functions. It can be passed to the cross_validate function to specify which metrics to calculate in the outer loop.
Default Metrics
By default, the following metrics are initialized:
-
R²: The coefficient of determination
-
MSE: Mean squared error
-
MAE: Mean absolute error
We decided againt using the RMSE as a default metric, because we would run into trouble wherever we would average over it.
RMSE should always be averaged as sqrt(mean(MSE_values))
and not as mean(sqrt(MSE_values))
.
Also, the standard deviation would be calculated incorrectly if RMSE is included at this point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
(dict) |
A dictionary that maps metric names to functions. |
required |
Example
Source code in flexcv/metrics.py
flexcv.metrics.mse_wrapper(y_valid, y_pred, y_train_in, y_pred_train)
This function is only used to calculate the objective function value for the hyperparameter optimization. In order to allow for customized objective functions it takes the validation and training data and the corresponding predictions as arguments. This can be useful to avoid overfitting. The sklearn MSE function had to be wrapped accordingly
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_valid |
array - like
|
Target in the validation set. |
required |
y_pred |
array - like
|
Predictions for the validation set. |
required |
y_train_in |
array - like
|
Target in the training set. |
required |
y_pred_train |
array - like
|
Predictions for the training set. |
required |
Returns:
Type | Description |
---|---|
float
|
Mean squared error. |