예제 #1
0
    feature_selection=True
    _,test_time,test_time_L=mss.learn_H_given_X_test_and_E_W(X_test=test_set_x,a_H_test=a_H_test,b_H_test=b_H_test,feature_selection=feature_selection,max_iter=max_iter,compute_variational_lower_bound=compute_variational_lower_bound,variational_lower_bound_min_rate=variational_lower_bound_min_rate,if_plot_lower_bound=if_plot_lower_bound,dir_save=dir_save,prefix=prefix,verb=verb,rng=rng)


    # classification using selected features
    classify_method="mlp"
    feature_selection=True
    method_param={"feature_extraction":False,"learning_rate":0.1, "alpha":0.01, "lambda_reg":0.00001, "alpha_reg":0.5, "n_hidden":None, "n_epochs":1000, "batch_size":100, "activation_func":"relu"}
    test_set_y_pred,test_set_y_prob,classification_training_time,classification_test_time=mss.classify(feature_selection=feature_selection,method=classify_method,method_param=method_param,rng=rng)
    #print test_set_y_prob
    perf,conf_mat=cl.perform(test_set_y,test_set_y_pred,numpy.unique(train_set_y))
    print perf
    print conf_mat
    # save classification result
    filename=prefix+"_classification_performance_"+ classify_method  + "_feat_sel_"+str(feature_selection)+"_max_num_feature_each_pattern_"+str(max_num_feature_each_pattern)+"_num_feat_sel_"+str(len(mss.numeric_ind_key_feat_for_classification))+".txt"
    cl.save_perform(dir_save,filename,perf=perf,std=None,conf_mat=conf_mat,classes_unique=unique_class_names,training_time=classification_training_time,test_time=classification_test_time)

mss.plot_heatmap(dir_save=dir_save,prefix=prefix+"_300dpi",pattern="All",rank_method="mean_basis_value",unique_class_names=unique_class_names, width=10, height=10, fontsize=4, fmt="png", dpi=300, colormap="hot", clrs=None, rng=rng)












예제 #2
0
                test_times = test_time
            else:
                perf = numpy.vstack((perf, perf_i))
                conf_mat = conf_mat + conf_mat_i
                training_times = training_times + training_time
                test_times = test_times + test_time

        # calculate mean performance and std
        perf_mean = numpy.mean(perf, axis=0)
        perf_std = numpy.std(perf, axis=0)

        print perf_mean
        print perf_std
        print conf_mat
        # save the performance
        save_dir = result_dir + "_".join(classes_unique)
        try:
            os.makedirs(save_dir)
        except OSError:
            pass
        filename = cell + "_" + str(wid) + "bp.txt"
        cl.save_perform(save_dir,
                        filename,
                        perf=perf_mean,
                        std=perf_std,
                        conf_mat=conf_mat,
                        classes_unique=classes_unique,
                        training_time=training_times,
                        test_time=test_times)
        gc_collect()
XM_view1_sort = numpy.argsort(XM_view[1].transpose(), axis=1)
XM_view1_sort = XM_view1_sort[:, ::-1]
numpy.savetxt(filename, XM_view1_sort, fmt="%s", delimiter="\t")
# calculate performance
perf, conf_mat = cl.perform(test_set_y,
                            test_subset_y_1d,
                            unique_classes=z_unique)
# save performance
cl.save_perform(path=dir_save,
                filename=prefix + "_mean_performances_" + method + ".txt",
                create_new_file=True,
                perf=perf,
                std=None,
                auroc=None,
                auroc_std=None,
                auprc=None,
                auprc_std=None,
                conf_mat=conf_mat,
                classes_unique=z_unique,
                pretraining_time=pretrain_time,
                training_time=None,
                test_time=None,
                stat_test=None)

#################################################################
#T=10000
#S=10
#model_mdbn.estimate_log_likelihood(X=[test_set_x,test_set_y01], NMF=100, base_rate_type="prior", beta=None, step_base=0.999, T=T, stepdist="even", S=S, sumout="auto", dir_save=dir_save, prefix=prefix+"_test_")
#model_mdbn.estimate_log_likelihood(X=[train_set_x,train_set_y01], NMF=100, base_rate_type="prior", beta=None, step_base=0.999, T=T, stepdist="even", S=S, sumout="auto", dir_save=dir_save, prefix=prefix+"_train_")
#
#print("result saved in: " + dir_save)
예제 #4
0
            # test
            test_set_y_pred,test_set_y_pred_prob,test_time=icnn.test_model(classifier, test_set_x_org)
            
            # evaluate classification performance
            perf_i,conf_mat_i=cl.perform(test_set_y_org,test_set_y_pred,numpy.unique(train_set_y_org))
            print perf_i
            print conf_mat_i
            if i==0:
                perf=perf_i
                conf_mat=conf_mat_i
                training_times=training_time
                test_times=test_time
            else:
                perf=numpy.vstack((perf,perf_i))
                conf_mat=conf_mat+conf_mat_i
                training_times=training_times + training_time
                test_times=test_times + test_time

        # after 10-fold CV, calculate mean performance and std
        perf_mean=numpy.mean(perf,axis=0)
        perf_std=numpy.std(perf,axis=0)

        print perf_mean
        print perf_std
        print conf_mat
        save_dir=result_dir + "_".join(classes_unique)
        filename=cell + "_" + str(wid) + "bp_np.txt"
        cl.save_perform(save_dir,filename,perf=perf_mean,std=perf_std,conf_mat=conf_mat,classes_unique=classes_unique,training_time=training_times,test_time=test_times)
        gc_collect()
        
예제 #5
0
####################################### test (Bayesian non-negative regression) ################################
_,test_time,test_time_L=model_fs.learn_H_given_X_test_and_E_W(X_test=test_set_x,a_H_test=a_H_test,b_H_test=b_H_test,feature_selection=True,max_iter=max_iter,compute_variational_lower_bound=True,variational_lower_bound_min_rate=1e-4,if_plot_lower_bound=True,dir_save=dir_save,prefix=prefix,verb=True,rng=rng)
model_fs.save_mf_test_result(dir_save,prefix)

###################################### classification #########################################
# classification using coefficients
classify_method="coef_sum"
feature_selection=True
test_set_y_pred,test_set_y_prob,classification_training_time,classification_test_time=model_fs.classify(feature_selection=feature_selection,method=classify_method,method_param=None,rng=rng)
#print test_set_y_prob
perf,conf_mat=cl.perform(test_set_y,test_set_y_pred,numpy.unique(train_set_y))
print perf
print conf_mat
# save classification result
filename=prefix+"_classification_performance_"+ classify_method  + "_feat_sel_"+str(feature_selection)+".txt"
cl.save_perform(dir_save,filename,perf=perf,std=None,conf_mat=conf_mat,classes_unique=unique_class_names,training_time=classification_training_time,test_time=classification_test_time)

# classification using the class-wise regression residuals
classify_method="regression_residual"
feature_selection=True
test_set_y_pred,test_set_y_prob,classification_training_time,classification_test_time=model_fs.classify(feature_selection=feature_selection,method=classify_method,method_param=None,rng=rng)
#print test_set_y_prob
perf,conf_mat=cl.perform(test_set_y,test_set_y_pred,numpy.unique(train_set_y))
print perf
print conf_mat
# save classification result
filename=prefix+"_classification_performance_"+ classify_method  + "_feat_sel_"+str(feature_selection)+".txt"
cl.save_perform(dir_save,filename,perf=perf,std=None,conf_mat=conf_mat,classes_unique=unique_class_names,training_time=classification_training_time,test_time=classification_test_time)

# classification using selected features
classify_method="mlp"