Shape · Statistics

Linear Regression

Fits a straight-line model of one column from one or more others. Outputs the coefficients, or your rows with predictions and residuals.

Also known as: Least squares, trend line

How it works

Pick the Target column and one or more Feature columns. Fit intercept is on by default. Rows with a NULL in the target or any feature are left out of the fit, and the node stops with an error when fewer rows remain than parameters. Output Coefficients gives a table with term and coefficient: an intercept row when fitted, one row per feature and an r_squared row. Predictions returns the rows used in the fit, so rows with a NULL in the target or any feature are dropped, with two appended columns, named predicted_target and residual_target unless you set Prediction column and Residual column. This node runs on the desktop with the rows in memory.

Inputs and outputs

Inputs

  • data — Table

Outputs

  • data — Table

Settings

The Attributes panel of Linear Regression, as in the app: the controls work, but nothing runs — there is no data behind it.

The same settings, as the Assistant writes them
{
  targetColumn: string
  featureColumns: string[]
  fitIntercept: boolean
  output: "coefficients"|"predictions"
  predictionColumn?: string
  residualColumn?: string
}

Example

Explain weekly sales from price and footfall: target sales, features price and footfall, output Coefficients.

termcoefficient
intercept412.6
price-18.3
footfall2.07
r_squared0.71