Main Content
Syntax
Description
example
err
= immse(X
,Y
)
calculates the mean-squared error (MSE) between the arrays X
and Y
. A lower MSE value indicates greater similarity between
X
and Y
.
Examples
collapse all
Calculate Mean-Squared Error in Noisy Image
Read image and display it.
ref = imread('pout.tif');
imshow(ref)
Create another image by adding noise to a copy of the reference image.
A = imnoise(ref,'salt & pepper', 0.02);
imshow(A)
Calculate mean-squared error between the two images.
err = immse(A, ref);
fprintf('n The mean-squared error is %0.4fn', err);
The mean-squared error is 353.7631
Input Arguments
collapse all
X
— Input array
numeric array
Input array, specified as a numeric array of any dimension.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Y
— Input array
numeric array
Input array, specified as a numeric array of the same size and data type as
X
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Output Arguments
collapse all
err
— Mean-squared error
positive number
Mean-squared error, returned as a positive number. The data type of err
is double
unless the input arguments are of data type
single
, in which case err
is of
data type single
Data Types: single
| double
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
immse
supports the generation of C
code (requires MATLAB®
Coder™). For more information, see Code Generation for Image Processing.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Version History
Introduced in R2014b
Main Content
mse
Mean squared normalized error performance function
Syntax
Description
example
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.
Examples
collapse all
Train Neural Network Using mse
Performance Function
This example 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
.
Train the network and evaluate performance.
net = train(net, x, t); y = net(x); perf = perform(net, t, y)
Alternatively, you can call mse
directly.
perf = mse(net, t, y, 'regularization', 0.01)
Input Arguments
collapse all
net
— Input matrix
matrix
Network you want to calculate the performance of, specified as a SeriesNetwork
or a
DAGNetwork
object.
t
— Targets
matrix | cell array
Targets, specified as a matrix or a cell array.
y
— Outputs
matrix | cell array
Outputs, specified as a matrix or a cell array.
ew
— Error weights
1
(default) | scalar
Error weights, specified as a scalar.
Output Arguments
collapse all
perf
— Network performance
scalar
Performance of the network as the mean squared errors.
Version History
Introduced before R2006a
17 авг. 2022 г.
читать 1 мин
Одной из наиболее распространенных метрик, используемых для измерения точности прогноза модели, является MSE , что означает среднеквадратичную ошибку .
Он рассчитывается как:
MSE = (1/n) * Σ(факт – прогноз) 2
куда:
- Σ — причудливый символ, означающий «сумма».
- n – размер выборки
- фактический – фактическое значение данных
- прогноз – прогнозируемое значение данных
Чем ниже значение MSE, тем лучше модель способна точно прогнозировать значения.
Чтобы вычислить MSE в MATLAB, мы можем использовать функцию mse(X, Y) .
В следующем примере показано, как использовать эту функцию на практике.
Пример: как рассчитать MSE в MATLAB
Предположим, у нас есть следующие два массива в MATLAB, которые показывают фактические значения и прогнозируемые значения для некоторой модели:
%create array of actual values and array of predicted values
actual = [34 37 44 47 48 48 46 43 32 27 26 24];
predicted = [37 40 46 44 46 50 45 44 34 30 22 23];
Мы можем использовать функцию mse(X, Y) для вычисления среднеквадратичной ошибки (MSE) между двумя массивами:
%calculate MSE between actual values and predicted values
mse(actual, predicted)
ans = 5.9167
Среднеквадратическая ошибка (MSE) этой модели оказывается равной 5,917 .
Мы интерпретируем это как означающее, что среднеквадратическая разница между предсказанными значениями и фактическими значениями составляет 5,917 .
Мы можем сравнить это значение с MSE, полученным другими моделями, чтобы определить, какая модель является «лучшей».
Модель с наименьшим MSE — это модель, которая лучше всего способна прогнозировать фактические значения набора данных.
Дополнительные ресурсы
В следующих руководствах объясняется, как рассчитать среднеквадратичную ошибку с помощью другого статистического программного обеспечения:
Как рассчитать среднеквадратичную ошибку (MSE) в Excel
Как рассчитать среднеквадратичную ошибку (MSE) в Python
Как рассчитать среднеквадратичную ошибку (MSE) в R