Machine Learning in Elixir: model accuracy

@seanmor5

In chapter 1, the accuracy of the model is 0.9666666. On my laptop I only get an accuracy of 0.5333333. Is that a problem? If not, maybe it’s worth calling out in the text so people like me don’t wonder if they did something wrong.

Of course maybe I did something wrong. :slight_smile:

There is an issue with how I transcribed one-hot encoding in the book. The correct version:

train_df
|> DF.pull(label_column)
|> Explorer.Series.to_list()
|> Enum.map(fn
"Iris-setosa" -> 0
"Iris-versicolor" -> 1
"Iris-virginica" -> 2
end)
|> Nx.tensor(type: :u8)
|> Nx.new_axis(-1)
|> Nx.equal(Nx.iota({1, 3}, axis: -1))
1 Like

Fixed the problem. Before I got a test accuracy of 0.
After updating y_train and y_test I got:
a train accuracy of: 0.9666680
a test accuracy of: 0.9666666

I encountered the same issue (poor test accuracy), but I think I’ve misunderstood the solution.

My understanding of the solution was to change the definition of train_categories to be as follows:

train_categories =
  train_df
  |> DF.pull(label_column)
  |> Explorer.Series.to_list()
  |> Enum.map(fn
    "Iris-setosa" -> 0
    "Iris-versicolor" -> 1
    "Iris-virginica" -> 2
  end)
  |> Nx.tensor(type: :u8)
  |> Nx.new_axis(-1)
  |> Nx.equal(Nx.iota({1, 3}, axis: -1))

(and analogously for test_categories.)

…but that doesn’t work for me. It leads to an error when trained_model_state is defined:

** (ArgumentError) cannot broadcast tensor of dimensions {120, 3, 3} to {120, 3}
    (nx 0.5.3) lib/nx/shape.ex:335: Nx.Shape.binary_broadcast/4
    (nx 0.5.3) lib/nx.ex:3570: Nx.element_wise_bin_op/4
    (axon 0.5.1) lib/axon/losses.ex:422: anonymous fn/2 in 
...