I have an embarrassingly parallel problem but have been wondering how to "design" function so that it achieves the end result
So, here is the sequential version
def train_weights(Xtr, ztr, Xte, zte):
regr = some_model()
regr.fit(Xtr, ztr)
error = np.mean((regr.predict(Xte) - zte) ** 2)
return regr.coef_, error
rnge = range(z_train.shape[0])
weights = []
errors = []
for i in rnge:
z_dim_tr = z_train[:,i]
z_dim_te = z_test[:, i]
weight, error = train_weights(X_train, z_dim_tr, X_test, z_dim_te)
weights.append(wgts)
errors.append(error)
So, I am just slicing a column from a matrix (train and test matrices) and then passing it to the function.. Note that, order of output matters.. which is the index of weight in weights list corresponds to a particular "i" and same for error.
How do i parallelize this?
train_weights()you wish to be done in parallel? While still keeping the order of the results appended to the lists?