I have a numpy array, and I am using sklearn to transform the array along the first axis. I also want to save the transformer object in a dict to use later in the code. Here is my code:
scalers_dict = {}
for i in range(train_data_numpy.shape[1]):
for j in range(train_data_numpy.shape[2]):
scaler = QuantileTransformer(n_quantiles=60000, output_distribution='uniform')
train_data_numpy[:,i,j] = scaler.fit_transform(train_data_numpy[:,i,j].reshape(-1,1)).reshape(-1)
scalers_dict[(i,j)] = scaler
My train_data_numpy is of shape (60000, 28,28). The problem is that this takes a very long time to process (train_data_numpy is MNIST dataset). I have an AMD Ryzen 5950X with 16 cores and I would like to parallelize this piece of code.
I know for example I could write something like this:
Parallel(n_jobs=16)(delayed(QuantileTransformer(n_quantiles=60000, output_distribution='uniform').fit_transform)(train_data_numpy[:,i,j].reshape(-1,1)) for j in range(train_data_numpy.shape[2]))
But this doesn't return the scaler object, and I don't know how to utilize Joblib for this task.