1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
function pred = quad_regress_pred(price, quantity)
days = size(price, 1) - size(quantity, 1);
product_count = size(price, 2);
test_count = size(quantity, 1);
test_set = 1:test_count;
pred_set = test_count+1:size(price, 1);
pred = zeros(days, product_count);
for i = 1:product_count
[a,b,c] = regress2(price(test_set, i), quantity(test_set, i));
pred(:, i) = a .* price(pred_set, i).^2 + b * price(pred_set, i) + c;
end
endfunction
function [a,b,c] = regress2(x, y)
abc = [ x.^2 x ones(length(x), 1) ] \ y;
a = abc(1);
b = abc(2);
c = abc(3);
endfunction
|