MATLAB: How to forecast an integer related to other 5 numbers

annforecast

I have 15 sets of data, you can see below:
33 48 47 68 79 => 6;
26 32 32 53 56 => 11;
60 17 19 57 59 => 16;
49 29 13 44 51 => 23;
0 19 25 44 73 => 24;
31 9 3 56 63 => 31;
3 22 24 43 39 => 37;
-3 4 39 32 52 => 41;
79 3 7 48 24 => 51;
9 26 24 49 5 => 68;
7 -2 0 57 41 => 75;
93 18 26 0 -2 => 76;
33 22 39 -1 5 => 103;
14 26 7 31 11 => 114;
17 -2 19 1 40 => 138;
Here first 5 data in each row are inputs and the last on in each row is output. I want to forecast result of other 4-numbers set of inputs; for example:
60 50 30 50 60 => ?;

Best Answer

If you don't have the Stats Toolbox, or the toolbox with regress() in it, you can use base MATLAB. Try a multiple linear regression like this:
clc; % Clear command window.
workspace; % Make sure the workspace panel is showing.
data = [...
33 48 47 68 79 6;
26 32 32 53 56 11;
60 17 19 57 59 16;
49 29 13 44 51 23;
0 19 25 44 73 24;
31 9 3 56 63 31;
3 22 24 43 39 37;
-3 4 39 32 52 41;
79 3 7 48 24 51;
9 26 24 49 5 68;
7 -2 0 57 41 75;
93 18 26 0 -2 76;
33 22 39 -1 5 103;
14 26 7 31 11 114;
17 -2 19 1 40 138]
numberOfObservations = size(data, 1);
% Set up the "x1" through "x5" values.
% Also add a contant term - see the help:
% MATLAB->Users Guide->Data Analysis->Regression Analysis->Programmatic Fitting->Multiple Regression.
inputs = [ones(numberOfObservations, 1) data(:, 1:5)]
% Extract out the "y" values.
observations = data(:, 6)
% Get the multiple linear coefficients.
coefficients = inputs \ observations % Will do a least square solution.
for row = 1 : length(observations)
predictedValue = coefficients(1) + ...
coefficients(2) * inputs(row, 1) + ...
coefficients(3) * inputs(row, 2) + ...
coefficients(4) * inputs(row, 3) + ...
coefficients(5) * inputs(row, 4) + ...
coefficients(6) * inputs(row, 5);
fprintf('For row #%d, predicted value = %.1f, observed value = %.1f\n',...
row, predictedValue, observations(row));
end