0

My goal is to create arrays:

[original array, mean value, std value]

The current code:

pd.DataFrame({'recall': [cv_result['test_recall'], cv_result['test_recall'].mean(), cv_result['test_recall'].std()]})

I wish to maybe call the array 3 times and do .mean(), std() function.

Jason Rich Darmawan
  • 1,607
  • 3
  • 14
  • 31
  • how so? Show us please. – CryptoFool Nov 13 '22 at 06:47
  • 1
    I wonder if you might find this question/answer to be of value: [Numpy mean AND variance from single function?](https://stackoverflow.com/questions/19391149/numpy-mean-and-variance-from-single-function). One of the answers proposes that `SciPy` can provide you both results in a single pass. – CryptoFool Nov 13 '22 at 06:49
  • `get_mean_std = lambda array: [array.mean(), array.std()]` -> call it `get_mean_std(array)` – Jason Rich Darmawan Nov 13 '22 at 06:49
  • Are you taking arithmetic means and std of percent values? These aren't going to mean what you think they mean. – Him Nov 13 '22 at 06:49
  • @Him i am not sure about std of percent values but the value is between 0 and 1. I do a `cross_validate` and want to get the mean of recall_score (if it high, it's good), also the deviation (if it is low, it's good). – Jason Rich Darmawan Nov 13 '22 at 06:53
  • @kidfrom - if `array == cv_result['test_recall']`, then I don't think your lambda reduces the amount of work over what the OPs code already does. The way Numpy works, `cv_result['test_recall'].mean()` is a single operation. Doing just `cv_result['test_recall']` doesn't really do anything at all, so if you think you're saving work by computing the "value" of `cv_result['test_recall']` just once, you're not. In my understanding, that's not the way Numpy works. – CryptoFool Nov 13 '22 at 07:03
  • @CryptoFool my goal is to shorten the amount of code I need to write. Tomorrow I got an exam to make 2 model with 2.5 hours (including EDA, data preprocessing). So it's good enough. Anyway, if numpy have agg function like pandas, I would love to try. – Jason Rich Darmawan Nov 13 '22 at 07:23
  • @kidfrom - Hey, sorry friend. I had missed that you were responding to your own question. That's why I thought you were being a bit presumptive about what the asker was asking. You weren't, of course, as you were the asker. – CryptoFool Nov 13 '22 at 16:33

0 Answers0