Exemple #1
0
def RNNMain():
    # positive and negative dataset
    positive = "../data/hsa_new.csv"
    negative = "../data/pseudo_new.csv"
    # partition the whole dataset into train(4/5) and test(1/5) datasets
    x_train_dataset,y_train_dataset,x_test_dataset,y_test_dataset = \
        dataSetPartition.train_test_partition(positive,negative)
    # train the model
    model = RNN_train(x_train_dataset,y_train_dataset)
    model_path = "RNN_model.h5"
    model.save(model_path)
    print("The model is saved as",model_path,"in the current directory.")

    # evaluate the performance 
    sensitivity,specifity,f1_score,mcc,accuracy =\
        test_evaluation(model_path,x_test_dataset,y_test_dataset)
    write_to_file(model_path,sensitivity,specifity,accuracy,f1_score,mcc)

    # Partition the whole dataset into 10 segments with every one segment for test and
    # and the remaining nine segments for train. All the data are stored in four list 
    x_train_list,y_train_list,x_validation_list,y_validation_list = \
        dataSetPartition.fold10_cv_partition(positive,negative)
    m = len(x_train_list)
    for i in range(m):
        model = RNN_train(x_train_list[i],y_train_list[i])
        model_path = "RNN_model_10fold"+str(i)+".h5"
        model.save(model_path)
        print(model_path,"is stored in the current directory.")
        # evaluate the performance 
        sensitivity,specifity,f1_score,mcc,accuracy =\
            test_evaluation(model_path,x_validation_list[i],y_validation_list[i])
        # write to file
        write_to_file(model_path,sensitivity,specifity,accuracy,f1_score,mcc)
def FCNMain():
    # positive and negative dataset
    positive = "../data/hsa_new.csv"
    negative = "../data/pseudo_new.csv"
    # partition the whole dataset into train(4/5) and test(1/5) datasets
    x_train_dataset,y_train_dataset,x_test_dataset,y_test_dataset = \
        dataSetPartition.train_test_partition(positive,negative)
    # train the model

    model = FCN_train(x_train_dataset, y_train_dataset, "FCNModel")
    model_path = "FCN_model.h5"
    model.save(model_path)
    print("The model is saved as", model_path, "in the current directory.")

    # evaluate the performance
    sensitivity,specifity,f1_score,mcc,accuracy =\
        test_evaluation(model_path,x_test_dataset,y_test_dataset)
    write_to_file(model_path, sensitivity, specifity, accuracy, f1_score, mcc)

    # Partition the whole dataset into 10 segments with every one segment for test and
    # and the remaining nine segments for train. All the data are stored in four list
    x_train_list,y_train_list,x_validation_list,y_validation_list = \
        dataSetPartition.fold5_cv_partition(positive,negative)
    sen = []
    spec = []
    acc = []
    f1 = []
    mc = []

    m = len(x_train_list)
    for i in range(m):
        name = "FCN_CV" + str(i)
        model = FCN_train(x_train_list[i], y_train_list[i], name)
        model_path = "FCN_model_5fold" + str(i) + ".h5"
        model.save(model_path)
        print(model_path, "is stored in the current directory.")
        # evaluate the performance
        sensitivity,specifity,f1_score,mcc,accuracy =\
            test_evaluation(model_path,x_validation_list[i],y_validation_list[i])
        sen.append(sensitivity)
        spec.append(specifity)
        acc.append(accuracy)
        f1.append(f1_score)
        mc.append(mcc)
        # write to file
        write_to_file(model_path, sensitivity, specifity, accuracy, f1_score,
                      mcc)
    write_to_file("FCN_model_performanceAVG", avg(sen), avg(spec), avg(acc),
                  avg(f1), avg(mc))
Exemple #3
0
def CNNMain():
    # positive and negative dataset
    positive = "../data/hsa_new.csv"
    negative = "../data/pseudo_new.csv"
    # partition the whole dataset into train(4/5) and test(1/5) datasets
    x_train_dataset,y_train_dataset,x_test_dataset,y_test_dataset = \
        dataSetPartition.train_test_partition(positive,negative)
    # train the model
    model = CNN_train(x_train_dataset, y_train_dataset)
    model_path = "CNN_model_proj2_1.h5"
    model.save(model_path)
    print("The model is saved as", model_path, "in the current directory.")

    # evaluate the performance
    sensitivity,specifity,f1_score,mcc,accuracy =\
        test_evaluation(model_path,x_test_dataset,y_test_dataset)
    write_to_file(model_path, sensitivity, specifity, accuracy, f1_score, mcc)
Exemple #4
0
def CNNMain():
    # positive and negative dataset
    positive = "../data/hsa_new.csv"
    negative = "../data/pseudo_new.csv"
    # partition the whole dataset into train(4/5) and test(1/5) datasets
    x_train_dataset,y_train_dataset,x_test_dataset,y_test_dataset = \
        dataSetPartition.train_test_partition(positive,negative)
    # train the model
    '''
    ler = [0.0001,0.0002,0.0003,0.0004,0.0005,0.0006,0.0007,0.0008,0.0009,0.001]
    drp = [0.35,0.40,0.45,0.50,0.55,0.60,0.65]
    #ps =  [2]
    dns = [32,64,128]
    '''

    model = CNN_train(x_train_dataset, y_train_dataset)
    model_path = "CNN_model.h5"
    model.save(model_path)
    print("The model is saved as", model_path, "in the current directory.")

    # evaluate the performance
    sensitivity,specifity,precision,f1_score,mcc,accuracy =\
        test_evaluation(model_path,x_test_dataset,y_test_dataset)
    write_to_file(model_path, sensitivity, specifity, precision, accuracy,
                  f1_score, mcc)

    # Partition the whole dataset into 10 segments with every one segment for test and
    # and the remaining nine segments for train. All the data are stored in four list
    x_train_list,y_train_list,x_validation_list,y_validation_list = \
        dataSetPartition.fold10_cv_partition(positive,negative)
    m = len(x_train_list)
    for i in range(m):
        model = CNN_train(x_train_list[i], y_train_list[i])
        model_path = "CNN_model_10fold" + str(i) + ".h5"
        model.save(model_path)
        print(model_path, "is stored in the current directory.")
        # evaluate the performance
        sensitivity,specifity,f1_score,mcc,accuracy =\
            test_evaluation(model_path,x_validation_list[i],y_validation_list[i])
        # write to file
        write_to_file(model_path, sensitivity, specifity, accuracy, f1_score,
                      mcc)
Exemple #5
0
""" Train the CNN model using dataset
"""
import sys
sys.path.append("../data") 
from CNNModel import CNN_model
import dataSetPartition
import keras
import os


def CNN_train(x_dataset,y_dataset):
    model = CNN_model()
    if os.path.exists("CNN_model_preTrained.h5"):
        print("load the weights")
        model.load_weights("CNN_model_preTrained.h5")
    model.fit(x_dataset,y_dataset,batch_size = 200, epochs = 600,\
          validation_split = 0.2)
    print("model train over")
    return model

if __name__ == "__main__":
    positive = "../data/hsa_new.csv" 
    negative = "../data/pseudo_new.csv"
    x_train_dataset,y_train_dataset,x_test_dataset,y_test_dataset = \
      dataSetPartition.train_test_partition(positive,negative)
    model = CNN_train(x_train_dataset,y_train_dataset)
#   model.save("CNN_model_preTrained.h5")
#   print("The model is saved as CNN_model_preTrained.h5 in the current directory")