Skip to content

Conversation

@krstopro
Copy link
Member

@krstopro krstopro commented Jan 11, 2026

Changes:

  • Fixes loss computation by adding average over sample losses
  • Fixes convergence criteria
  • Adds input validation in predict and predict_proba
  • Polishes the code slightly
  • Adds more unit tests

Fixes #301

tol,
w_optimizer_state,
b_optimizer_state,
opts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, when you have too many arguments like this, you can wrap the arguments that don't change (are fixed in the loop) in a map and pass it down. Helps clean up while loops and Elixir signatures!

Copy link
Member Author

@krstopro krstopro Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for tensors as well, right?
Apart from that, CI is failing. I am working on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I am not sure I understood. 😅

Would having a while loop as {result, state} = while ... where state is a map work? Is this something new in Nx?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works. It is quite old i think :)

@krstopro
Copy link
Member Author

Alright, this was way more work than I thought :)
I managed to remove the optimizer completely by explicitly computing the gradients and using line search for adapting the learning rate.
@josevalim If this gets merged I would suggest releasing a new version. Logistic regression is a fundamental algorithm and there have been important changes to others (e.g. DBSCAN).

@josevalim
Copy link
Contributor

It is your decision to merge it! I can ship a new version afterwards!

@krstopro
Copy link
Member Author

It is your decision to merge it! I can ship a new version afterwards!

Alright then, merged. :)

@krstopro
Copy link
Member Author

P.S. I am having issues compiling EXLA 0.9.2 on my M1 Mac. Perhaps we should bump the version?

@krstopro krstopro merged commit 76de8c3 into elixir-nx:main Jan 16, 2026
2 checks passed
@krstopro krstopro changed the title Logistic regression fix Logistic regression updates Jan 16, 2026
@josevalim
Copy link
Contributor

Released (and feel free to bump Nx as well!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in Cross-Entropy Implementation inside Scholar.Linear.LogisticRegression?

2 participants