示例#1
0
def func_getDecision_Scores_spam(dataset, data_train, data_test, labels_train):

    #sklearn_OCSVM
    result = sklearn_OCSVM_linear(data_train, data_test)
    df_spam_vs_ham_scores["sklearn-OCSVM-Linear-Train"] = result[0]
    df_spam_vs_ham_scores["sklearn-OCSVM-Linear-Test"] = result[1]

    result = sklearn_OCSVM_rbf(data_train, data_test)
    df_spam_vs_ham_scores["sklearn-OCSVM-RBF-Train"] = result[0]
    df_spam_vs_ham_scores["sklearn-OCSVM-RBF-Test"] = result[1]
    print("Finished sklearn_OCSVM_linear")

    # # sklearn _OCSVM_explicit
    # result = sklearn_OCSVM_explicit_linear(data_train,data_test)
    # df_spam_vs_ham_scores["sklearn-OCSVM-explicit-Linear-Train"] = result[0]
    # df_spam_vs_ham_scores["sklearn-OCSVM-explicit-Linear-Test"] =  result[1]

    # result = sklearn_OCSVM_explicit_sigmoid(data_train,data_test)
    # df_spam_vs_ham_scores["sklearn-OCSVM-explicit-Sigmoid-Train"] = result[0]
    # df_spam_vs_ham_scores["sklearn-OCSVM-explicit-Sigmoid-Test"] = result[1]

    # print ("Finished sklearn _OCSVM_explicit")

    # #One Class NN Explicit
    # result = One_Class_NN_explicit_linear(data_train,data_test)
    # df_spam_vs_ham_scores["One_Class_NN_explicit-Linear-Train"] = result[0]
    # df_spam_vs_ham_scores["One_Class_NN_explicit-Linear-Test"] =  result[1]

    # result = One_Class_NN_explicit_sigmoid(data_train,data_test)
    # df_spam_vs_ham_scores["One_Class_NN_explicit-Sigmoid-Train"] = result[0]
    # df_spam_vs_ham_scores["One_Class_NN_explicit-Sigmoid-Test"] = result[1]

    # print ("Finished One Class NN Explicit")

    # result = tf_OneClass_NN_linear(data_train,data_test)
    # df_spam_vs_ham_scores["tf_OneClass_NN-Linear-Train"] = result[0]
    # df_spam_vs_ham_scores["tf_OneClass_NN-Linear-Test"] =  result[1]

    # result = tf_OneClass_NN_sigmoid(data_train,data_test)
    # df_spam_vs_ham_scores["tf_OneClass_NN-Sigmoid-Train"] = result[0]
    # df_spam_vs_ham_scores["tf_OneClass_NN-Sigmoid-Test"] = result[1]

    print("Finished tf_OneClass_NN_linear")

    # Y = labels_train
    # Y = Y.tolist()
    # labels_train = [[i] for i in Y]
    # result = tflearn_OneClass_NN_linear(data_train,data_test,labels_train)
    # df_spam_vs_ham_scores["tflearn_OneClass_NN-Linear-Train"] = result[0]
    # df_spam_vs_ham_scores["tflearn_OneClass_NN-Linear-Test"] =  result[1]

    # result = tflearn_OneClass_NN_Sigmoid(data_train,data_test,labels_train)
    # df_spam_vs_ham_scores["tflearn_OneClass_NN-Sigmoid-Train"] = result[0]
    # df_spam_vs_ham_scores["tflearn_OneClass_NN-Sigmoid-Test"] = result[1]
    # print ("Finished tflearn_OneClass")

    # print (type(df_spam_vs_ham_scores))
    # print ( (df_spam_vs_ham_scores.keys()))

    return df_spam_vs_ham_scores
示例#2
0
def func_getDecision_Scores_cifar(dataset, data_train, data_test, raw_train,
                                  raw_test, data_train_ae2, data_test_ae2,
                                  modelpath):

    print "Calling.....", func_getDecision_Scores_cifar
    result = CAE_OCSVM_Linear(data_train, data_test, nu)
    df_cifar_scores["cae_ocsvm-linear-Train"] = result[0]
    df_cifar_scores["cae_ocsvm-linear-Test"] = result[1]

    df_cifar_time["cae_ocsvm-linear-Train"] = result[2]
    df_cifar_time["cae_ocsvm-linear-Test"] = result[3]

    print("Finished cae_ocsvm-linear")

    result = CAE_OCSVM_RBF(data_train, data_test, nu)
    df_cifar_scores["cae_ocsvm-rbf-Train"] = result[0]
    df_cifar_scores["cae_ocsvm-rbf-Test"] = result[1]

    df_cifar_time["cae_ocsvm-rbf-Train"] = result[2]
    df_cifar_time["cae_ocsvm-rbf-Test"] = result[3]
    print("Finished cae_ocsvm-rbf")

    result = tf_OneClass_NN_linear(data_train, data_test, nu)
    df_cifar_scores["tf_OneClass_NN-Linear-Train"] = result[0]
    df_cifar_scores["tf_OneClass_NN-Linear-Test"] = result[1]

    df_cifar_time["tf_OneClass_NN-Linear-Train"] = result[2]
    df_cifar_time["tf_OneClass_NN-Linear-Test"] = result[3]

    print("Finished tf_OneClass_NN_linear")

    result = tf_OneClass_NN_sigmoid(data_train, data_test, nu)
    df_cifar_scores["tf_OneClass_NN-Sigmoid-Train"] = result[0]
    df_cifar_scores["tf_OneClass_NN-Sigmoid-Test"] = result[1]

    df_cifar_time["tf_OneClass_NN-Sigmoid-Train"] = result[2]
    df_cifar_time["tf_OneClass_NN-Sigmoid-Test"] = result[3]
    print("Finished tf_OneClass_NN_sigmoid")

    result = tf_OneClass_NN_relu(data_train, data_test, nu)
    df_cifar_scores["tf_OneClass_NN-Relu-Train"] = result[0]
    df_cifar_scores["tf_OneClass_NN-Relu-Test"] = result[1]
    print("Finished tf_OneClass_NN_relu")

    result = sklearn_OCSVM_linear(raw_train, raw_test, nu)

    df_cifar_scores["sklearn-OCSVM-Linear-Train"] = result[0]
    df_cifar_scores["sklearn-OCSVM-Linear-Test"] = result[1]
    print result[2], result[3]
    df_cifar_time["sklearn-OCSVM-Linear-Train"] = result[2]
    df_cifar_time["sklearn-OCSVM-Linear-Test"] = result[3]
    print("Finished sklearn_OCSVM_linear")

    result = sklearn_OCSVM_rbf(raw_train, raw_test, nu)
    df_cifar_scores["sklearn-OCSVM-RBF-Train"] = result[0]
    df_cifar_scores["sklearn-OCSVM-RBF-Test"] = result[1]

    df_cifar_time["sklearn-OCSVM-RBF-Train"] = result[2]
    df_cifar_time["sklearn-OCSVM-RBF-Test"] = result[3]
    print("Finished sklearn_OCSVM_RBF")

    result = sklearn__RPCA_OCSVM(raw_train, raw_test, nu)
    df_cifar_scores["rpca_ocsvm-Train"] = result[0]
    df_cifar_scores["rpca_ocsvm-Test"] = result[1]
    ## Training and Testing Times recorded
    df_cifar_time["rpca_ocsvm-Train"] = result[2]
    df_cifar_time["rpca_ocsvm-Test"] = result[3]

    print("Finished rpca_ocsvm")

    result = sklearn_IsolationForest(raw_train, raw_test)
    df_cifar_scores["isolation-forest-Train"] = result[0]
    df_cifar_scores["isolation-forest-Test"] = result[1]
    ## Training and Testing Times recorded
    df_cifar_time["isolation-forest-Train"] = result[2]
    df_cifar_time["isolation-forest-Test"] = result[3]
    print("Finished isolation-forest")

    result = AE2_SVDD_Linear(data_train_ae2, data_test_ae2, nu, modelpath)
    df_cifar_scores["ae_svdd-linear-Train"] = result[0]
    df_cifar_scores["ae_svdd-linear-Test"] = result[1]
    ## Training and Testing Times recorded
    df_cifar_time["ae_svdd-linear-Train"] = result[2]
    df_cifar_time["ae_svdd-linear-Test"] = result[3]
    print("Finished ae_ocsvm-linear")

    result = AE2_SVDD_RBF(data_train_ae2, data_test_ae2, nu, modelpath)
    df_cifar_scores["ae_svdd-rbf-Train"] = result[0]
    df_cifar_scores["ae_svdd-rbf-Test"] = result[1]

    ## Training and Testing Times recorded
    df_cifar_time["ae_svdd-rbf-Train"] = result[2]
    df_cifar_time["ae_svdd-rbf-Test"] = result[3]
    print("Finished ae_ocsvm-rbf")

    # Write a CSV file for Cifar-10 data consisting of Methods, Train and test time
    #Method, Train, Test
    methods = [
        'OC-NN-Linear', 'OC-NN-Sigmoid', 'CAE-OCSVM-Linear', 'CAE-OCSVM-RBF',
        'AE2-SVDD-Linear', 'AE2-SVDD-RBF', 'OCSVM-Linear', 'OCSVM-RBF',
        'RPCA_OCSVM', 'Isolation_Forest'
    ]
    write_training_test_results(df_cifar_time, methods)

    return df_cifar_scores
示例#3
0
def func_getDecision_Scores_usps_old(dataset, data_train, data_test):

    # if(autoencoder == "yes"):
    # 	[data_train,data_test] = usps_autoencoder_representation(data_train, data_test)

    #sklearn_OCSVM
    result = sklearn_OCSVM_linear(data_train, data_test)
    df_mnist_scores["sklearn-OCSVM-Linear-Train"] = result[0]
    df_mnist_scores["sklearn-OCSVM-Linear-Test"] = result[1]

    result = sklearn_OCSVM_rbf(data_train, data_test)
    df_mnist_scores["sklearn-OCSVM-RBF-Train"] = result[0]
    df_mnist_scores["sklearn-OCSVM-RBF-Test"] = result[1]
    print("Finished sklearn_OCSVM_linear")

    # sklearn _OCSVM_explicit
    result = sklearn_OCSVM_explicit_linear(data_train, data_test)
    df_mnist_scores["sklearn-OCSVM-explicit-Linear-Train"] = result[0]
    df_mnist_scores["sklearn-OCSVM-explicit-Linear-Test"] = result[1]

    result = sklearn_OCSVM_explicit_sigmoid(data_train, data_test)
    df_mnist_scores["sklearn-OCSVM-explicit-Sigmoid-Train"] = result[0]
    df_mnist_scores["sklearn-OCSVM-explicit-Sigmoid-Test"] = result[1]

    print("Finished sklearn _OCSVM_explicit")

    #One Class NN Explicit
    result = One_Class_NN_explicit_linear(data_train, data_test)
    df_mnist_scores["One_Class_NN_explicit-Linear-Train"] = result[0]
    df_mnist_scores["One_Class_NN_explicit-Linear-Test"] = result[1]

    result = One_Class_NN_explicit_sigmoid(data_train, data_test)
    df_mnist_scores["One_Class_NN_explicit-Sigmoid-Train"] = result[0]
    df_mnist_scores["One_Class_NN_explicit-Sigmoid-Test"] = result[1]

    print("Finished One Class NN Explicit")

    result = tf_OneClass_NN_linear(data_train, data_test)
    df_mnist_scores["tf_OneClass_NN-Linear-Train"] = result[0]
    df_mnist_scores["tf_OneClass_NN-Linear-Test"] = result[1]
    print("Finished tf_OneClass_NN_linear")

    result = tf_OneClass_NN_sigmoid(data_train, data_test)
    df_mnist_scores["tf_OneClass_NN-Sigmoid-Train"] = result[0]
    df_mnist_scores["tf_OneClass_NN-Sigmoid-Test"] = result[1]

    print("Finished tf_OneClass_NN_sigmoid")

    # Y = labels_train
    # Y = Y.tolist()
    # labels_train = [[i] for i in Y]
    # result = tflearn_OneClass_NN_linear(data_train,data_test,labels_train)
    # df_mnist_scores["tflearn_OneClass_NN-Linear-Train"] = result[0]
    # df_mnist_scores["tflearn_OneClass_NN-Linear-Test"] =  result[1]
    #
    # result = tflearn_OneClass_NN_Sigmoid(data_train,data_test,labels_train)
    # df_mnist_scores["tflearn_OneClass_NN-Sigmoid-Train"] = result[0]
    # df_mnist_scores["tflearn_OneClass_NN-Sigmoid-Test"] = result[1]
    # print ("Finished tflearn_OneClass")

    # print (type(df_mnist_scores))
    # print ( (df_mnist_scores.keys()))

    return df_mnist_scores
示例#4
0
def func_getDecision_Scores_pfam(dataset, data_train, data_test,
                                 data_train_biovec, data_test_biovec,
                                 data_train_ae, data_test_ae):
    print "Calling.....", func_getDecision_Scores_pfam

    result = LSTMAE_OCSVM_Linear(data_train, data_test, nu)
    df_pfam_scores["lstm_ocsvm-linear-Train"] = result[0]
    df_pfam_scores["lstm_ocsvm-linear-Test"] = result[1]

    df_pfam_time["lstm_ocsvm-linear-Train"] = result[2]
    df_pfam_time["lstm_ocsvm-linear-Test"] = result[3]

    print("Finished lstm_ocsvmlinear")

    result = LSTMAE_OCSVM_RBF(data_train, data_test, nu)
    df_pfam_scores["lstm_ocsvm-rbf-Train"] = result[0]
    df_pfam_scores["lstm_ocsvm-rbf-Test"] = result[1]

    df_pfam_time["lstm_ocsvm-rbf-Train"] = result[2]
    df_pfam_time["lstm_ocsvm-rbf-Test"] = result[3]

    print("Finished lstm_ocsvm-rbf")

    result = tf_OneClass_LSTM_AE_NN_linear(data_train, data_test, nu)
    df_pfam_scores["tf_OneClass_NN-Linear-Train"] = result[0]
    df_pfam_scores["tf_OneClass_NN-Linear-Test"] = result[1]

    df_pfam_time["tf_OneClass_NN-Linear-Train"] = result[2]
    df_pfam_time["tf_OneClass_NN-Linear-Test"] = result[3]

    print("Finished tf_OneClass_NN_linear")

    result = tf_OneClass_LSTM_AE_NN_sigmoid(data_train, data_test, nu)
    df_pfam_scores["tf_OneClass_NN-Sigmoid-Train"] = result[0]
    df_pfam_scores["tf_OneClass_NN-Sigmoid-Test"] = result[1]

    df_pfam_time["tf_OneClass_NN-Sigmoid-Train"] = result[2]
    df_pfam_time["tf_OneClass_NN-Sigmoid-Test"] = result[3]

    print("Finished tf_OneClass_NN_sigmoid")

    result = tf_OneClass_LSTM_AE_NN_Relu(data_train, data_test, nu)
    df_pfam_scores["tf_OneClass_NN-Relu-Train"] = result[0]
    df_pfam_scores["tf_OneClass_NN-Relu-Test"] = result[1]

    print("Finished tf_OneClass_NN_sigmoid")

    result = sklearn_OCSVM_linear(data_train_biovec, data_test_biovec, nu)
    df_pfam_scores["sklearn-OCSVM-Linear-Train"] = result[0]
    df_pfam_scores["sklearn-OCSVM-Linear-Test"] = result[1]

    df_pfam_time["sklearn-OCSVM-Linear-Train"] = result[2]
    df_pfam_time["sklearn-OCSVM-Linear-Test"] = result[3]

    print("Finished sklearn_OCSVM_linear")

    result = sklearn_OCSVM_rbf(data_train_biovec, data_test_biovec, nu)
    df_pfam_scores["sklearn-OCSVM-RBF-Train"] = result[0]
    df_pfam_scores["sklearn-OCSVM-RBF-Test"] = result[1]

    df_pfam_time["sklearn-OCSVM-RBF-Train"] = result[2]
    df_pfam_time["sklearn-OCSVM-RBF-Test"] = result[3]
    print("Finished sklearn_OCSVM_RBF")

    result = sklearn_RPCA_OCSVM_Linear(data_train_biovec, data_test_biovec, nu)
    df_pfam_scores["rpca_ocsvm-Linear-Train"] = result[0]
    df_pfam_scores["rpca_ocsvm-Linear-Test"] = result[1]

    df_pfam_time["rpca_ocsvm-Linear-Train"] = result[2]
    df_pfam_time["rpca_ocsvm-Linear-Test"] = result[3]

    result = sklearn_RPCA_OCSVM_rbf(data_train_biovec, data_test_biovec, nu)
    df_pfam_scores["rpca_ocsvm-rbf-Train"] = result[0]
    df_pfam_scores["rpca_ocsvm-rbf-Test"] = result[1]

    ## Pfam time
    df_pfam_time["rpca_ocsvm-rbf-Train"] = result[2]
    df_pfam_time["rpca_ocsvm-rbf-Test"] = result[3]

    print("Finished rpca_ocsvm")

    result = sklearn_IsolationForest(data_train_biovec, data_test_biovec)
    df_pfam_scores["isolation-forest-Train"] = result[0]
    df_pfam_scores["isolation-forest-Test"] = result[1]

    df_pfam_time["isolation-forest-Train"] = result[2]
    df_pfam_time["isolation-forest-Test"] = result[3]

    print("Finished isolation-forest")

    result = AE_OCSVM_Linear(data_train_ae, data_test_ae, nu)
    df_pfam_scores["ae_svdd-linear-Train"] = result[0]
    df_pfam_scores["ae_svdd-linear-Test"] = result[1]

    df_pfam_time["ae_svdd-linear-Train"] = result[2]
    df_pfam_time["ae_svdd-linear-Test"] = result[3]

    print("Finished ae_svdd-linear")

    result = AE_OCSVM_RBF(data_train_ae, data_test_ae, nu)
    df_pfam_scores["ae_svdd-rbf-Train"] = result[0]
    df_pfam_scores["ae_svdd-rbf-Test"] = result[1]

    df_pfam_time["ae_svdd-rbf-Train"] = result[2]
    df_pfam_time["ae_svdd-rbf-Test"] = result[3]

    print("Finished ae_svdd-rbf")

    # Write a CSV file for Cifar-10 data consisting of Methods, Train and test time
    # Method, Train, Test
    methods = [
        'OC-NN-Linear', 'OC-NN-Sigmoid', 'LSTM-AE-OCSVM-Linear',
        'LSTM-AE-OCSVM-RBF', 'AE2-SVDD-Linear', 'AE2-SVDD-RBF',
        'RPCA_OCSVM_linear', 'RPCA_OCSVM_rbf', 'Isolation_Forest',
        'OCSVM-Linear', 'OCSVM-RBF'
    ]

    write_training_test_results(df_pfam_time, methods)

    return df_pfam_scores
示例#5
0
def func_getDecision_Scores_mnist(dataset, data_train, data_test,
                                  data_train_ae2, data_test_ae2,
                                  data_train_cae, data_test_cae):

    #sklearn_OCSVM
    result = sklearn_OCSVM_linear(data_train, data_test, nu)
    df_mnist_scores["sklearn-OCSVM-Linear-Train"] = result[0]
    df_mnist_scores["sklearn-OCSVM-Linear-Test"] = result[1]

    df_mnist_time["sklearn-OCSVM-Linear-Train"] = result[2]
    df_mnist_time["sklearn-OCSVM-Linear-Test"] = result[3]

    result = sklearn_OCSVM_rbf(data_train, data_test, nu)
    df_mnist_scores["sklearn-OCSVM-RBF-Train"] = result[0]
    df_mnist_scores["sklearn-OCSVM-RBF-Test"] = result[1]

    df_mnist_time["sklearn-OCSVM-RBF-Train"] = result[2]
    df_mnist_time["sklearn-OCSVM-RBF-Test"] = result[3]
    print("Finished sklearn_OCSVM_linear")

    result = tf_mnist_OneClass_NN_linear(data_train_cae, data_test_cae)
    df_mnist_scores["tf_OneClass_NN-Linear-Train"] = result[0]
    df_mnist_scores["tf_OneClass_NN-Linear-Test"] = result[1]

    df_mnist_time["tf_OneClass_NN-Linear-Train"] = result[2]
    df_mnist_time["tf_OneClass_NN-Linear-Test"] = result[3]

    print("Finished tf_OneClass_NN_linear")

    result = tf_mnist_OneClass_NN_sigmoid(data_train_cae, data_test_cae)
    df_mnist_scores["tf_OneClass_NN-Sigmoid-Train"] = result[0]
    df_mnist_scores["tf_OneClass_NN-Sigmoid-Test"] = result[1]

    df_mnist_time["tf_OneClass_NN-Sigmoid-Train"] = result[2]
    df_mnist_time["tf_OneClass_NN-Sigmoid-Test"] = result[3]

    print("Finished tf_OneClass_NN_sigmoid")

    result = tf_mnist_OneClass_NN_Relu(data_train_cae, data_test_cae)
    df_mnist_scores["tf_OneClass_NN-Relu-Train"] = result[0]
    df_mnist_scores["tf_OneClass_NN-Relu-Test"] = result[1]

    print("Finished tf_OneClass_NN_sigmoid")

    result = sklearn__RPCA_OCSVM(data_train, data_test, nu)
    df_mnist_scores["rpca_ocsvm-Train"] = result[0]
    df_mnist_scores["rpca_ocsvm-Test"] = result[1]

    df_mnist_time["rpca_ocsvm-Train"] = result[2]
    df_mnist_time["rpca_ocsvm-Test"] = result[3]
    print("Finished rpca_ocsvm")

    result = sklearn_IsolationForest(data_train, data_test)
    df_mnist_scores["isolation-forest-Train"] = result[0]
    df_mnist_scores["isolation-forest-Test"] = result[1]

    df_mnist_time["isolation-forest-Train"] = result[2]
    df_mnist_time["isolation-forest-Test"] = result[3]
    print("Finished isolation-forest")

    result = AE2_SVDD_Linear(data_train_ae2, data_test_ae2, nu)
    df_mnist_scores["ae_svdd-linear-Train"] = result[0]
    df_mnist_scores["ae_svdd-linear-Test"] = result[1]

    df_mnist_time["ae_svdd-linear-Train"] = result[2]
    df_mnist_time["ae_svdd-linear-Test"] = result[3]
    print("Finished ae_ocsvm-linear")

    result = AE2_SVDD_RBF(data_train_ae2, data_test_ae2, nu)
    df_mnist_scores["ae_svdd-rbf-Train"] = result[0]
    df_mnist_scores["ae_svdd-rbf-Test"] = result[1]

    df_mnist_time["ae_svdd-rbf-Train"] = result[2]
    df_mnist_time["ae_svdd-rbf-Test"] = result[3]
    print("Finished ae_ocsvm-sigmoid")

    result = CAE_OCSVM_Linear(data_train_cae, data_test_cae, nu)
    df_mnist_scores["cae_ocsvm-linear-Train"] = result[0]
    df_mnist_scores["cae_ocsvm-linear-Test"] = result[1]

    df_mnist_time["cae_ocsvm-linear-Train"] = result[2]
    df_mnist_time["cae_ocsvm-linear-Test"] = result[3]
    print("Finished cae_ocsvm-linear")

    result = CAE_OCSVM_RBF(data_train_cae, data_test_cae, nu)
    df_mnist_scores["cae_ocsvm-rbf-Train"] = result[0]
    df_mnist_scores["cae_ocsvm-rbf-Test"] = result[1]

    df_mnist_time["cae_ocsvm-rbf-Train"] = result[2]
    df_mnist_time["cae_ocsvm-rbf-Test"] = result[3]

    print("Finished cae_ocsvm-rbf")

    # Write a CSV file for Cifar-10 data consisting of Methods, Train and test time
    # Method, Train, Test
    methods = [
        'OC-NN-Linear', 'OC-NN-Sigmoid', 'CAE-OCSVM-Linear', 'CAE-OCSVM-RBF',
        'AE2-SVDD-Linear', 'AE2-SVDD-RBF', 'OCSVM-Linear', 'OCSVM-RBF',
        'RPCA_OCSVM', 'Isolation_Forest'
    ]
    write_training_test_results(df_mnist_time, methods)

    return df_mnist_scores