summaryrefslogtreecommitdiff
path: root/log_regress_pred.m
blob: 3c9044164253632ce0e697c09227741e765f5cb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function pred = log_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] = regress_log(price(test_set, i), quantity(test_set, i));
		pred(:, i) = a * log(price(pred_set, i)) + b;
	end

endfunction


function [a,b] = regress_log(x, y)
	ab = [ log(x) ones(length(x), 1) ] \ y;
	a = ab(1);
	b = ab(2);;
endfunction