I always get find myself in state of confusion when dealing with a multi-dimensional array. Imaging having the following array of arrays, where each array contains feature importance scores (3-features), for each class in the dataset (5-classes). The dataset contains 4 samples in all.
arr = np.random.randn(5,4,3).round(1)
arr
array([[[ 0.7, -0.1, 0.6], # class 0 feature importances
[-0.8, -0.7, 1.4],
[ 1.4, -0.1, 1.4],
[-1.8, -1.2, -1.6]],
[[-0.3, 2.1, 0.5], # class 1 feature importances
[-1.2, 1.4, -0.4],
[ 0. , -1. , 0.8],
[-0.8, 2.3, 0.3]],
[[ 0.2, 0.6, -0.1], # class 2 feature importances
[-1.8, -0.2, 1.2],
[-0.5, 0.5, 1. ],
[ 1.3, 0.4, -2.6]],
[[-1. , 0.8, -0.4], # class 3 feature importances
[ 1.2, 1.5, -0.5],
[ 0.1, -0.5, 0.8],
[ 2.5, -1.6, -0.6]],
[[-1.2, 0.3, -0.9], # class 4 feature importances
[ 1. , -1. , -0.5],
[ 0.3, 1.4, 0.5],
[-2.3, 0.6, 0.2]]])
I am interested in computing the mean absolute value of feature importances across the classes (overrall). Ideally the resultant arrar should be a rank 1 (3,) since there are three features:
Feature1 = sum( abs(0.7,-0.8, 1.4, -1.8, -0.3, -1.2, 0.0, -0.8, 0.2, -1.8, -0.5, 1.3,
-1.0, 1.2, 0.1, 2.5, -1.2, 1.0, 0.3,, -2.3) ) / 12 # n = 12