1

I am trying to obtain the std of this output using numpy.std()

[[array([0.92473118, 0.94117647]), array([0.98850575, 0.69565217]), array([0.95555556, 0.8       ]), 0.923030303030303], [array([0.85555556, 0.8       ]), array([0.95061728, 0.55172414]), array([0.9005848 , 0.65306122]), 0.8353285811932428]]

To obtain that output I used the code (it goes through a loop, in this example, it went through two iterations)

precision, recall, fscore, support = precision_recall_fscore_support(np.argmax(y_test_0, axis=-1),                                                                              np.argmax(probas_, axis=-1))

eval_test_metric = [precision, recall, fscore, avg_fscore]
test_metric1.append(eval_test_metric)

std_matrix1 = np.std(test_metric1, axis=0)

I would like to get an output similar in structure to when I do np.mean(), Please excuse the 'precision', 'recall' I just made that in my code for clarity.

dr_test_metric = dict(zip(['specificity avg', 'sensitivity avg', 'ppv avg', 'npv avg'], np.mean(test_metric2, axis=0)))

print(dr_test_metric,'\n')

output, (where 0.89014337 in 'precision avg': array([0.89014337, 0.87058824] is the average of precision of class 0 for my model and 0.8705 is the average of the precision for class 1 for my model)

{'precision avg': array([0.89014337, 0.87058824]), 'recall avg': array([0.96956152, 0.62368816]), 'fscore avg': array([0.92807018, 0.72653061]), 'avg_fscore avg': 0.8791794421117729} 
MikeDoho
  • 552
  • 2
  • 5
  • 18
  • 1
    I would re-think how you're storing your outputs. `numpy` doesn't like jagged arrays – user3483203 May 01 '19 at 17:03
  • So you mean exclude the last part of the array? I could try that. – MikeDoho May 01 '19 at 17:05
  • @user3483203 .....how are people so much smarter than me haha. Thanks it looks like it worked! Out of curiosity, what made you think that was the issue? – MikeDoho May 01 '19 at 17:17
  • 1
    I would recommend reading up on how numpy stores it's data. If you have an array with a funky shape and dtype `object`, you're not really utilizing numpy how it's meant to be used, and many vectorized methods won't work. – user3483203 May 01 '19 at 17:19
  • @user3483203 thank you. I will take a look. I appreciate your help! – MikeDoho May 01 '19 at 17:22
  • 1
    I would recommend starting here: https://docs.scipy.org/doc/numpy-1.13.0/reference/internals.html – user3483203 May 01 '19 at 17:22
  • 1
    This is a common error when trying to do math on object dtype arrays. So the next quesrion is why that dtype an shape? – hpaulj May 01 '19 at 17:31
  • @hpaulj For the shape, I am ashamed to admit laziness. In fact, the last value isnt necessary/probably isnt proper to calculate. For dtype, I didnt select it per say, it was the output. The dtype didnt have to be what it was. The first think I was trying was changing the type to see if that would help. Ultimately correcting the shape worked. – MikeDoho May 01 '19 at 17:43
  • 1
    When the inputs are ragged, object dtype is the default. Such array is similar to a list, containing python objects rather than pure numbers. – hpaulj May 01 '19 at 17:57
  • @hpaulj Thank you for your help! I plan to review the link that was suggested above to fill in the gaps in my knowledge as well – MikeDoho May 01 '19 at 18:03

0 Answers0