def nmf_kfold(data, k, n_runs=<NUM_LIT:10>, **nmf_params):
<EOL>nmf = NMF(k)<EOL>W_list = []<EOL>kf = KFold(n_splits=n_runs, shuffle=True)<EOL>for train_index, test_index in kf.split(data.T):<EOL><INDENT>W = nmf.fit_transform(data[:,train_index])<EOL>W_list.append(W)<EOL><DEDENT>W_stacked = np.hstack(W_list)<EOL>nmf_w = nmf.fit_transform(W_stacked)<EOL>nmf_h = nmf.components_<EOL>H_new = data.T.dot(nmf_w).T<EOL>nmf2 = NMF(k, init='<STR_LIT>')<EOL>nmf_w = nmf2.fit_transform(data, W=nmf_w, H=H_new)<EOL>H_new = nmf2.components_<EOL>return nmf_w, H_new<EOL>
Runs K-fold ensemble topic modeling (Belford et al. 2017)