loss_function_mse
Loss function: Mean Square Error.
mse = loss_function_mse(y_true, y_pred)
Input variables
Name | Description | Type |
---|---|---|
y_true | True values | List |
y_pred | Predicted values | List |
Output variables
Name | Description | Type |
---|---|---|
mse | Mean Square Error | Float |
Problem
\[f(\mathbf{y}_{\text{true}}, \mathbf{y}_{\text{pred}}) = \frac{1}{n} \cdot \sum_{i=1}^{n} (y_{\text{true},i} - y_{\text{pred},i})^2\] | (1) |
\(n\) is the number of samples.
Example 1
Considering the true values \(\mathbf{y}_{\text{true}} = [1.0, 2.0, 3.0, 4.0, 5.0]\) and predicted values \(\mathbf{y}_{\text{pred}} = [1.2, 2.3, 2.9, 4.2, 5.3]\), what is the resulting Mean Absolute Error (MSE)?
# Example data
y_true_example = [1.0, 2.0, 3.0, 4.0, 5.0]
y_pred_example = [1.2, 2.3, 2.9, 4.2, 5.3]
# Call function
mse_value = loss_function_mse(y_true_example, y_pred_example)
# Output details
print("Mean Square Error (MSE): {:.4f}".format(mse_value))
Mean Square Error (MSE): 0.0540