# Efficient way of doing linear regression

**URL:** <https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232>\
**Category:** Performance\
**Tags:** regression\
**Created:** [November 18, 2019, 5:21pm UTC](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232 "2019-11-18T17:21:15Z")\
**Posts on this page:** 1\
**Showing post:** 38

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [August 12, 2020, 2:19am UTC](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232/38 "2020-08-12T02:19:39Z")

</div>

You can do exactly that already. I will agree that it isn’t as “in your face” or easy to find as it could be though.

```julia
using GLM
x = [...]
y = [...]
reg = lm(x,y)
scatter(x,y)
plot!(x,predict(reg),label="R^2=$(r2(reg))")

```

also `Plots.jl` or `StatsPlots.jl` (I can’t remember which one) provides a direct option in the `scatter` command to put the regression line on the plot for you.

---

_[View the full topic](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232)._
