This commit is contained in:
Anton Nesterov 2024-09-25 13:19:01 +02:00
parent 7e0085ffbd
commit 8b44d43c83
No known key found for this signature in database
GPG key ID: 59121E8AE2851FB5

9
expr.ts Normal file
View file

@ -0,0 +1,9 @@
import pl from "npm:nodejs-polars"
export function residuals(x: pl.Expr, y: pl.Expr): pl.Expr {
const xM = x.minus(x.mean())
const yM = y.minus(y.mean())
const xMSQ = xM.pow(2)
const beta = xM.dot(yM).div(xMSQ.sum())
return yM.minus(beta.mul(xM))
}