Given a multi-class confusion matrix, perform error analysis to characterize the model's mistakes.
The input cm is an n x n matrix (list of lists or numpy array) where cm[i][j] is the number of samples whose true class is i and predicted class is j. Diagonal entries correspond to correct predictions.
Implement error_analysis(cm) that returns a dictionary with the following keys (in this order):
'per_class_error_rate': a list of length n. Entry i is the fraction of true-class-i samples that were misclassified, i.e. (row_sum_i - cm[i][i]) / row_sum_i. If a row sum is 0, use 0.0.'overall_error_rate': total off-diagonal mass divided by the total count, i.e. 1 - accuracy. If the total is 0, use 0.0.'most_confused_pair': a list [i, j] with i != j indicating the off-diagonal cell with the largest count (the most frequent confusion). Break ties by smallest i, then smallest j. If n >= 2, always return some valid pair (defaulting to [0, 1] when all off-diagonal entries are zero).'worst_class': the integer index of the class with the highest per-class error rate. Break ties by smallest index.Do not round inside the function — return raw floats. Tests will format as needed.