Search code examples
pythonmatrixscikit-learnscaling

StandardScaler on list with matrix as list element


I have a List with patients. Each patient has a (n x m) matrix with values.

enter image description here

Now I want to normalize the data over all patients with mean/std using the StandardScaler.

The problem is that it apparently cannot include several list entries.

is there a possibility do use this command or do I need to do it by hand with a for loop?

Cheers

p.s.: I get

ValueError: setting an array element with a sequence.

This is due to the matrix sizes while StandardScaler is supposedly only working with arrays.


Solution

  • Suppose you have an array of patient data matrices like this:

    my_patient_data_X
    

    Then you can do this:

    my_patient_data_X = [StandardScaler().fit_transform(X) for X in my_patient_data_X]
    

    Would this achieve what you want?