OLS / Multiple linear regression in polars

84 views Asked by At

After reading this answer, I was wondering if there was any (fast) implementation of OLS with multiple variables implemented in polars?

Someone mentioned 'coordinate descent', I'm wondering if a polar implementation is available?

Thanks for your help!

1

There are 1 answers

0
Dean MacGregor On BEST ANSWER

There's an extension called polars_ds that does OLS. You just just pip install polars_ds

See cells 6 through 12 of the link for example usage. Here's just the simplest case copy-pasted

# Least Square (Linear Regression)
df.select(
    pl.col("y").num.lstsq(pl.col("x1"), pl.col("x2"), add_bias=False)
)
shape: (1, 1)
y
list[f64]
[2.0, -1.0]

In that case the list output are the coefficients for x1 and x2 respectively.