# Best way for linear regression problem on product features

**URL:** <https://discourse.julialang.org/t/best-way-for-linear-regression-problem-on-product-features/127786>\
**Category:** General Usage\
**Tags:** performance, regression, qr\
**Created:** [April 7, 2025, 7:52am UTC](https://discourse.julialang.org/t/best-way-for-linear-regression-problem-on-product-features/127786 "2025-04-07T07:52:46Z")\
**Posts on this page:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 7, 2025, 7:24pm UTC](https://discourse.julialang.org/t/best-way-for-linear-regression-problem-on-product-features/127786/24 "2025-04-07T19:24:20Z")

</div>

> [@stevengj](#):
>
> Right, your equation is equivalent to

In fact, this was not correct. Minimizing \Vert Y - Z B X^T \Vert (or the equivalent expression with Kronecker products) looks at _all_ the elements of Z B X^T, when in fact you only want to minimize the differences in the _diagonal_ elements.

So, @mikmoore’s solution is actually not applicable here because it is solving the wrong problem (my fault), in addition to being too slow (because \operatorname{diagm}(y) is too big here).

The iterative algorithm ([above](https://discourse.julialang.org/t/best-way-for-linear-regression-problem-on-product-features/127786/5)) as well as the direct algorithm ([above](https://discourse.julialang.org/t/best-way-for-linear-regression-problem-on-product-features/127786/8)) solve the correct problem, though.

---

_[View the full topic](https://discourse.julialang.org/t/best-way-for-linear-regression-problem-on-product-features/127786)._
