Main Content

regression

(Not recommended) Perform linear regression of shallow network outputs on targets

regression is not recommended. Use fitlm (Statistics and Machine Learning Toolbox) instead. For more information, see Version History.

Description

[r,m,b] = regression(t,y) calculates the linear regression between each element of the network response and the corresponding target.

This function takes cell array or matrix target t and output y, each with total matrix rows of N, and returns the regression values, r, the slopes of regression fit, m, and the y-intercepts, b, for each of the N matrix rows.

example

[r,m,b] = regression(t,y,'one') combines all matrix rows before regressing, and returns single scalar regression, slope, and offset values.

Examples

collapse all

This example shows how to train a feedforward network and calculate and plot the regression between its targets and outputs.

Load the training data.

[x,t] = simplefit_dataset;

The 1-by-94 matrix x contains the input values and the 1-by-94 matrix t contains the associated target output values.

Construct a feedforward neural network with one hidden layer of size 20.

net = feedforwardnet(20);

Train the network net using the training data.

net = train(net,x,t);

Figure Neural Network Training (05-Sep-2024 19:13:45) contains an object of type uigridlayout.

Estimate the targets using the trained network.

y = net(x);

Calculate and plot the regression between its targets and outputs.

[r,m,b] = regression(t,y)
r = 
1.0000
m = 
1.0000
b = 
1.0878e-04
plotregression(t,y)

Figure Regression (plotregression) contains an axes object. The axes object with title : R=1, xlabel Target, ylabel Output ~= 1*Target + 0.00011 contains 3 objects of type line. One or more of the lines displays its values using only markers These objects represent Y = T, Fit, Data.

Input Arguments

collapse all

Network targets, specified as a matrix or cell array.

Network outputs, specified as a matrix or cell array.

Output Arguments

collapse all

Regression value, returned as a scalar.

Slope of regression fit, returned as a scalar.

Offset of regression fit, returned as a scalar.

Version History

Introduced in R2010b

collapse all

R2020b: regression is not recommended

regression is not recommended. To fit a linear regression model, use fitlm (Statistics and Machine Learning Toolbox) instead.

See Also

| | (Statistics and Machine Learning Toolbox)