I am currently using pandas.crosstab to generate the confusion matrix of my classifiers after testing. Unfortunately, sometimes my classifier fails, and classifies every signal as a single label (instead of multiple labels). pandas.crosstab generates a single vector (or a non-square matrix) in that case instead of a square matrix.
As example, my ground truth would be
true_data = pandas.Series([1, 1, 2, 2, 3, 3, 4, 4, 5, 5])
and my predicted data is
pred_data = pandas.Series([3, 3, 2, 3, 2, 1, 1, 3, 4, 1])
Applying pandas.crosstab(true_data, pred_data, dropna=False)
gives
col_0 1 2 3 4
row_0
1 0 0 2 0
2 0 1 1 0
3 1 1 0 0
4 1 0 1 0
5 1 0 0 1
Is there a way to get
col_0 1 2 3 4 5
row_0
1 0 0 2 0 0
2 0 1 1 0 0
3 1 1 0 0 0
4 1 0 1 0 0
5 1 0 0 1 0
instead, i.e. leaving the matrix square and filling the missing labels with 0
?