Machine Learning in Elixir: Missing option in confusion matrix (page 104)

Version: B1.0

On page 104 the code:

Scholar.Metrics.confusion_matrix(test_targets, test_preds)

throws an error: required :num_classes option not found, received options: []

I think the code should be:

Scholar.Metrics.confusion_matrix(test_targets, test_preds, num_classes: 3)

Another similar error on page 107, the following code fails:

model = Scholar.Neighbors.KNearestNeighbors.fit(train_inputs, train_targets)

I think it should be:

model = Scholar.Neighbors.KNearestNeighbors.fit(train_inputs, train_targets, num_classes: 3)

In addition the accuracy I reach is lower ( 0.5555555820465088) and the Confussion matrix:

nx.Tensor<
s64[3][3]
EXLA.Backend<host:0, 0.2777305747.1958084637.177673>
[
[11, 0, 0],
[6, 5, 3],
[7, 0, 4]
]

The dimension of the model is f32[3][13] instead of f32[13][3].

The prediction function also needs the model as input parameter.

Thanks for catching these, I’ve updated the book to fix these issues! As far as accuracy, it’s possible it may just be a one-time thing. Is your accuracy consistently lower than what the book states?