summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quad_regress_pred.m23
-rw-r--r--run_tests.m2
2 files changed, 25 insertions, 0 deletions
diff --git a/quad_regress_pred.m b/quad_regress_pred.m
new file mode 100644
index 0000000..aef8822
--- /dev/null
+++ b/quad_regress_pred.m
@@ -0,0 +1,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
diff --git a/run_tests.m b/run_tests.m
index b7b1a83..358c6dc 100644
--- a/run_tests.m
+++ b/run_tests.m
@@ -6,6 +6,8 @@
% plot prediction quallity
calc_error('mean', q(29:42, :), mean_pred(q(1:28, :), 14));
calc_error('regress', q(29:42, :), regress_pred(p, q(1:28, :)));
+% quadratic just for reference, it sucks more than mean-predicition
+calc_error('quad regress', q(29:42, :), quad_regress_pred(p, q(1:28, :)));
calc_error('log regress', q(29:42, :), log_regress_pred(p, q(1:28, :)));
calc_error('sevenday', q(29:42, :), repmat(sevenday_pred(q(1:28, :), 4), 2, 1));
calc_error('random', q(29:42, :), rand_pred(q(1:28, :), 14));