Skip to content

compute_linear_regression_coefficients

compute_linear_regression_coefficients(x, y)

Description

Returns linear regression coefficients from x, y columns.

Compute linear regression of (x, y) and return slope and intercept coefficients so that:

y ~= slope * x + intercept

Examples

Call or Deploy compute_linear_regression_coefficients ?
Call compute_linear_regression_coefficients directly

The easiest way to use bigfunctions

  • compute_linear_regression_coefficients function is deployed in 39 public datasets for all of the 39 BigQuery regions.
  • It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)

Public BigFunctions Datasets

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...
Deploy compute_linear_regression_coefficients in your project

Why deploy?

  • You may prefer to deploy compute_linear_regression_coefficients in your own project to build and manage your own catalog of functions.
  • This is particularly useful if you want to create private functions (for example calling your internal APIs).
  • Get started by reading the framework page

Deployment

compute_linear_regression_coefficients function can be deployed with:

pip install bigfunctions
bigfun get compute_linear_regression_coefficients
bigfun deploy compute_linear_regression_coefficients

Example with a generated time serie

create temp table sample_data as (

  select
      x,
      2 * x + 1 as y  -- example relationship: y = 2x + 1
  from unnest([1.0, -1.0, 3.0, -3.0, 5.0, -5.0]) as x

);

select bigfunctions.eu.compute_linear_regression_coefficients(x, y)
from sample_data
create temp table sample_data as (

  select
      x,
      2 * x + 1 as y  -- example relationship: y = 2x + 1
  from unnest([1.0, -1.0, 3.0, -3.0, 5.0, -5.0]) as x

);

select bigfunctions.us.compute_linear_regression_coefficients(x, y)
from sample_data
create temp table sample_data as (

  select
      x,
      2 * x + 1 as y  -- example relationship: y = 2x + 1
  from unnest([1.0, -1.0, 3.0, -3.0, 5.0, -5.0]) as x

);

select bigfunctions.europe_west1.compute_linear_regression_coefficients(x, y)
from sample_data
+-----------------------------------------+
| coefficients                            |
+-----------------------------------------+
| struct(2.0 as slope, 1.0 as intercept)
 |
+-----------------------------------------+

Need help or Found a bug using compute_linear_regression_coefficients?
Get help using compute_linear_regression_coefficients

The community can help! Engage the conversation on Slack

We also provide professional suppport.

Report a bug about compute_linear_regression_coefficients

If the function does not work as expected, please

  • report a bug so that it can be improved.
  • or open the discussion with the community on Slack.

We also provide professional suppport.

Spread the word!

BigFunctions is fully open-source. Help make it a success by spreading the word!

Share on Add a on