FeatureAgglomerative on multimodal

hello ,

            X_train_1, X_val_1, y_train, y_val = X1[train], X1[val], y[train], y[val]
            X_train_2, X_val_2 = X2[train], X2[val]

            ward = FeatureAgglomeration(n_clusters=1000, connectivity=connectivity,linkage='ward')
            X_red1 = ward.fit_transform(X_train_1)
            label1= np.ravel(ward.labels_)
            X_val1= ward.transform(X_val_1)

            ward2 = FeatureAgglomeration(n_clusters=1000,connectivity=connectivity,linkage='ward')
            X_red_2= ward2.fit_transform(X_train_2)                
            X_val2= ward2.transform(X_val_2)
            label2= np.ravel(ward2.labels_)

            X_red= np.concatenate((X_red1,X_red2),axis=1)         #X_red of shape (100,2000)
            X_val = np.concatenate((X_val1,X_val2),axis=1)          #X_val of shape(50,2000)

            mod = SVR()
            mod.fit(X_red,y_train)
            coef= mod.coef_                #coef of shape (2000,)

To return to voxel space, one can use:

  incidence= coo_matrix(
                (np.ones(n_voxels), (labels, np.arange(n_voxels))),
                shape=(n_parcels, n_voxels), dtype=np.float32).tocsc()
        inv_sum_col = dia_matrix(
                (np.array(1. / incidence.sum(axis=1)).squeeze(), 0),
                shape=(n_parcels, n_parcels))    
        incidence = inv_sum_col * incidence
        w = coef * incidence

I want to return to voxel space from global “coef” of shape (2000,) : coef is the coef of model trained on the concatenation of X_red1 (of shape (100,1000) and X_red2 (of shape (100,1000)), the problem is i have two labels (label1 for ward (with 1000 parcels) and label2 for ward2 (1000 parcels) ) .
how can i return to voxel space from “coef” (taking into acount label1 and label2) ?

thank you very much ! @bthirion

You may want to use something like:
coef_img1 = ward.inverse_transform(mod.coef_[:1000])
coef_img2 = ward2.inverse_transform(mod.coef_[1000:])
HTH,
Bertrand

MANAGED BY INCF