Main Content


Mean squared normalized error performance function




To use mean squared error with deep learning, use regressionLayer, or use the dlarray method mse.

perf = mse(net,t,y,ew) takes a neural network, net, a matrix or cell array of targets, t, a matrix or cell array of outputs, y, and error weights, ew, and returns the mean squared error.

This function has two optional parameters, which are associated with networks whose net.trainFcn is set to this function:

  • 'regularization' can be set to any value between 0 and 1. The greater the regularization value, the more squared weights and biases are included in the performance calculation relative to errors. The default is 0, corresponding to no regularization.

  • 'normalization' can be set to 'none' (the default); 'standard', which normalizes errors between -2 and 2, corresponding to normalizing outputs and targets between -1 and 1; and 'percent', which normalizes errors between -1 and 1. This feature is useful for networks with multi-element outputs. It ensures that the relative accuracy of output elements with differing target value ranges are treated as equally important, instead of prioritizing the relative accuracy of the output element with the largest target value range.

You can create a standard network that uses mse with feedforwardnet or cascadeforwardnet. To prepare a custom network to be trained with mse, set net.performFcn to 'mse'. This automatically sets net.performParam to a structure with the default optional parameter values.

mse is a network performance function. It measures the network’s performance according to the mean of squared errors.


collapse all

This example shows shows how to train a neural network using the mse performance function.

Here a two-layer feedforward network is created and trained to estimate body fat percentage using the mse performance function and a regularization value of 0.01.

[x, t] = bodyfat_dataset;
net = feedforwardnet(10);
net.performParam.regularization = 0.01;

MSE is the default performance function for feedforwardnet.

ans = 

Train the network and evaluate performance.

net = train(net, x, t);
y = net(x);
perf = perform(net, t, y)
perf = 20.7769

Alternatively, you can call mse directly.

perf = mse(net, t, y, 'regularization', 0.01)
perf = 20.7769

Input Arguments

collapse all

Network you want to calculate the performance of, specified as a SeriesNetwork or a DAGNetwork object.

Targets, specified as a matrix or a cell array.

Outputs, specified as a matrix or a cell array.

Error weights, specified as a scalar.

Output Arguments

collapse all

Performance of the network as the mean squared errors.

See Also

Introduced before R2006a