MCPcopy
hub / github.com/ContextLab/hypertools / fill_missing

Function fill_missing

hypertools/tools/format_data.py:166–185  ·  view source on GitHub ↗

Fill missing values using PPCA

(x)

Source from the content-addressed store, hash-verified

164
165
166def fill_missing(x):
167 """Fill missing values using PPCA"""
168 # ppca if missing data
169 m = PPCA()
170 x_stacked = np.vstack(x)
171 m.fit(data=x_stacked)
172 x_pca = m.transform()
173
174 # if the whole row is missing, return nans
175 all_missing = [idx for idx, a in enumerate(x_stacked) if np.all(np.isnan(a))]
176 if len(all_missing)>0:
177 for i in all_missing:
178 x_pca[i, :] = np.nan
179
180 # get the original lists back
181 if len(x)>1:
182 x_split = np.cumsum([i.shape[0] for i in x][:-1])
183 return list(np.split(x_pca, x_split, axis=0))
184 else:
185 return [x_pca]

Callers 1

format_dataFunction · 0.85

Calls 3

fitMethod · 0.95
transformMethod · 0.95
PPCAClass · 0.85

Tested by

no test coverage detected