djaouen
Hello,
I am working through the examples in the new book, Machine Learning in Elixir and I am having an issue with poor accuracy in Chapter 1’s example. You can find the Livebook I created here: machine-learning-in-elixir/machine-learning-in-elixir-chapter-1.livemd at main · danieljaouen/machine-learning-in-elixir · GitHub
And here is the accuracy I am getting on my machine:
Batch: 0, accuracy: 0.0666667
%{
0 => %{
"accuracy" => #Nx.Tensor<
f32
0.06666667014360428
>
}
}
However, the training accuracy seems fine:
Epoch: 0, Batch: 450, accuracy: 0.8331868 loss: 0.5048826
Epoch: 1, Batch: 450, accuracy: 0.8779556 loss: 0.4173653
Epoch: 2, Batch: 450, accuracy: 0.9101056 loss: 0.3732252
Epoch: 3, Batch: 450, accuracy: 0.9288760 loss: 0.3434850
Epoch: 4, Batch: 450, accuracy: 0.9367946 loss: 0.3209158
Epoch: 5, Batch: 450, accuracy: 0.9416718 loss: 0.3026979
Epoch: 6, Batch: 450, accuracy: 0.9494675 loss: 0.2874412
Epoch: 7, Batch: 450, accuracy: 0.9583363 loss: 0.2743504
Epoch: 8, Batch: 450, accuracy: 0.9583363 loss: 0.2629215
Epoch: 9, Batch: 450, accuracy: 0.9626405 loss: 0.2528131
Not sure what I am doing wrong here. Any help? Thanks in advance!
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
t12a
96% accuracy is not bad. IMHO.
bdarla
Your code is correct (in accordance with the book).
In some runs, I also noticed low accuracy. This is because of the small dataset (150 samples).
If you re-run the steps from the shuffle step and below, then you will receive different results every time. In some cases, it can easily be 96% accuracy. Just, rerun the experiment.
djaouen
Am I looking at the accuracy score wrong? Is it
1 - 0.0667and not0.0667? Sorry for being so confused lol.djaouen
I tried re-running it, and now it’s even worse:
Is there a way to pull the actual predictions from
Axon.Loop.evaluator? I tried removing the accuracy metric, but that just returns an empty map. How can I compare the predicted values withy_test?grossvogel
I ran into this also, and decided it had to be some kind of typo with how the test set is set up. After a lot of head scratching, I think there’s a more subtle error with the setup of the test data. I believe when the species are assigned their positions in the one-hot encoding vector, that order is determined by the order in which the species are encountered in the test and training data.
For instance, if the species of the first 3 rows of the training set are
"Iris-virginica", "Iris-setosa", ""Iris-versicolor", then those entries in thetrain_ydata will look like[1, 0, 0], [0, 1, 0], [0, 0, 1]and the model will learn to predict[1, 0, 0]if the features match what it’s learned about “Iris-virginica.”If the species are encountered in a different order in the test data, then we may end up with “Iris-virginica” having the 2nd position instead of the first in the
test_ydata, so the model will predict[1, 0, 0]but the scoring logic will be comparing against[0, 1, 0]grossvogel
You can see what the model is predicting for the test data with Axon.predict/4
grossvogel
I had a few more minutes to play with this, and so far it looks like we can get better results by processing the x and y data into tensors before splitting up test and training sets.
djaouen
Thanks, I will try this. Could it be that the one-hot encoding creates different category values since we are encoding different sets of labels? I think that might explain the low accuracy, if so.
Edit: Yep, I just tried it, and this seems to have fixed the problem. Thanks, @grossvogel!
shawn_leong
I ran into the same problem too.
First place I had looked was the accompanying Livebooks from PragProg that clued me in to the ordering.
Here’s the code from the accompanying Livebook:
I have to say I really prefer @grossvogel’s alternative code that uses
Explorer.Series.cast(:category)instead since Explorer already does provide a convenient method for one-hot encoding.I’ve reported this issue to @seanmor5 as an Errata on the official devtalk forum referencing this thread.
Edit: Added the link to download the accompanying Livebooks from PragProg.