def fit(self): """ """ i = 0 errs_models = [] errs_null_models = [] nb_coefs = [] nb_models = [] intercepts = [] print '\n######## cross validation\n####parameters:{0}'\ .format(self.ssrge_params) ssrge = SSrGE(**self.ssrge_params) kfold = KFold(n_splits=self.n_folds, shuffle=True) for train, test in kfold.split(self.SNV_mat): i += 1 print '\n## fold nb {0}'.format(i) X_train = self.SNV_mat[train] Y_train = self.GE_mat.T[train].T X_test = self.SNV_mat[test] Y_test = self.GE_mat.T[test].T ssrge.fit(X_train, Y_train) score, score_null = ssrge.score(X_test, Y_test) errs_models.append(score) errs_null_models.append(score_null) nb_coefs.append(len(ssrge.eeSNV_weight)) nb_models.append(len(ssrge.intercepts)) intercepts.append(np.mean(ssrge.intercepts.values())) return (np.mean(errs_models), np.mean(errs_null_models), np.mean(nb_coefs), np.mean(nb_models), np.mean(intercepts))
def test_ssrge_rank_gene(self): """test ssrge and rank genes and snvs""" from garmire_SSrGE.examples import create_example_matrix_v2 from garmire_SSrGE.ssrge import SSrGE X, Y, gene_id_list, snv_id_list = create_example_matrix_v2() ssrge = SSrGE(snv_id_list=snv_id_list, gene_id_list=gene_id_list, nb_ranked_features=2, alpha=0.01) ssrge.fit(X, Y) self.assertTrue(ssrge.eeSNV_weight) Xr = ssrge.transform(X) self.assertTrue(Xr.sum()) self.assertTrue(Xr.shape[0] == X.shape[0]) self.assertTrue(Xr.shape[1] < X.shape[1]) snv_ranked = ssrge.rank_eeSNVs() self.assertTrue(snv_ranked) self.assertTrue(len(ssrge.retained_snvs) == ssrge.nb_ranked_features) self.assertTrue(len(ssrge.retained_genes) == ssrge.nb_ranked_features) score = ssrge.score(X, Y) self.assertTrue(score[0] < score[1]) subgroup = ssrge.rank_features_for_a_subgroup(range(10)) self.assertTrue(len(subgroup.gene_expr_distrib[gene_id_list[0]]) == 10) self.assertTrue(subgroup.snv_weights_distrib) self.assertTrue(subgroup.exp_snv_distrib_comp)
def test_ssrge_cnv(self): """test ssrge procedure with cnv matrix""" from garmire_SSrGE.examples import create_example_matrix_v3 from garmire_SSrGE.ssrge import SSrGE X, Y, C, W = create_example_matrix_v3() ssrge = SSrGE(alpha=0.01) ssrge.fit(X, Y, C) self.assertTrue(ssrge.eeSNV_weight) Xr = ssrge.transform(X) self.assertTrue(Xr.sum()) self.assertTrue(Xr.shape[0] == X.shape[0]) self.assertTrue(Xr.shape[1] < X.shape[1]) snv_ranked = ssrge.rank_eeSNVs() self.assertTrue(snv_ranked) score = ssrge.score(X, Y) self.assertTrue(score[0] < score[1])
def test_ssrge_elasticnet(self): """test ssrge procedure with elasticnet model""" from garmire_SSrGE.examples import create_example_matrix_v1 from garmire_SSrGE.ssrge import SSrGE X, Y, W = create_example_matrix_v1() ssrge = SSrGE(alpha=0.01, model='ElasticNet') ssrge.fit(X, Y) self.assertTrue(ssrge.eeSNV_weight) Xr = ssrge.transform(X) self.assertTrue(Xr.sum()) self.assertTrue(Xr.shape[0] == X.shape[0]) self.assertTrue(Xr.shape[1] <= X.shape[1]) snv_ranked = ssrge.rank_eeSNVs() self.assertTrue(snv_ranked) score = ssrge.score(X, Y) self.assertTrue(score[0] < score[1])