This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This code is based on my other Gist "Simple linear regression in Javascript" (https://gist.github.com/patrickpissurno/ea0dc4039f075fbaf398619761bd9044) | |
-- There might be a more efficient way to do this in SQL | |
-- This function is resposible for computing the weights for the ax + b equation | |
CREATE OR REPLACE FUNCTION linear_regression(x_array decimal(15,2)[], y_array decimal(15,2)[]) RETURNS decimal(15,2)[] AS $$ | |
DECLARE | |
slope decimal(15,2); | |
intercept decimal(15,2); | |
n integer; |