I have code that creates an INDArray with 1000 predictions and I want to compare them with 1000 solutions to make a confusion matrix. Now, I already found out roughly how to do that:
Evaluation eval = new Evaluation();
Yhat.setShapeAndStride(new int[]{1,1000}, new int[]{1000,1});
Ytest.setShapeAndStride(new int[]{1,1000}, new int[]{1000,1});
eval.eval(Ytest, Yhat);
System.out.println(eval.stats());
Problem 1: you already see I had to reshape the Arrays. Originally they had shape:
Rank: 1, DataType: LONG, Offset: 0, Order: c, Shape: [1000], Stride: [1]
and the code would throw a runtime error complaining “Labels and predictions must always be rank 2 or higher”. This version doesn’t throw an error, but it’s clearly still the wrong shape: it results in a confusion matrix that thinks there are 1000 classes. What shape and “stride” should I use for the matrix, and what’s the stride for anyway?
Problem 2: I figured out that what the Evaluation wants is a matrix with 0s and 1s, where each row is a data point, the columns are potential classes, and there’s a 1 in the column that marks the correct class. However, my data is in the shape [ 5, 2, 6…] meaning the first data point is predicted to be class 5, and so on.
So, either:
a) How do I transform the matrix into a 0s and 1s matrix?
b) How do I make a confusion matrix out of a “non-binary” matrix?