Esempio n. 1
0
    def SVM(self):
        '''
        SVM function
        :return:
        results to be saved by the adder function
        '''
        global opter
        global losser
        alg = 3
        if self.iterator == 0:
            Optimizers = ['rbf', 'linear', 'poly']

            loss = [1, 2, 3, 4, 5]
            test2 = 0

            for elements in range(len(Optimizers)):
                for elemento in range(len(loss)):
                    alg = 1
                    data = self.data

                    X_train, X_test, y_train, y_test = converter_1(data,
                                                                   SVM=True)

                    loader = SVM(X_train, X_test, y_train, y_test,
                                 Optimizers[elements], loss[elemento])
                    y_test, y_pred = loader.svm()

                    _, _, _, _, num, num2 = feedbackdata(y_test, y_pred)

                    if num2 <= 1:
                        num2 = 1
                    teste = num * (np.power(num, (1 / num2)))
                    if teste > test2:
                        opter = Optimizers[elements]
                        losser = loss[elemento]
                        test2 = teste

        data = self.data

        X_train, X_test, y_train, y_test = converter_1(data, SVM=True)

        start = timeit.default_timer()

        loader = SVM(X_train, X_test, y_train, y_test, opter, losser)
        y_test, y_pred = loader.svm()
        end = timeit.default_timer()
        totaltime = round(end - start, 2)

        Name = 'SVM' + '-' + self.dataname
        tn, fp, fn, tp, detection_rate, false_positive_rate = feedbackdata(
            y_test, y_pred)
        results = [
            tn, fp, fn, tp, detection_rate, false_positive_rate, totaltime
        ]

        self.adder(results, Name, alg, opter, losser)
Esempio n. 2
0
    def Iocsvm(self):

        alg = 0
        data = self.data

        X_train, X_val, X_test, y_train, y_val, y_test = converter_1(
            data,
            onClassClassification=True,
            shuffle=False,
            test_size=0.25,
            validation_size=0.25)

        start = timeit.default_timer()
        loader = OneClassSVM(X_train, X_val, X_test, y_train, y_val, y_test)

        y_test, y_pred = loader.prediction()

        end = timeit.default_timer()
        totaltime = round(end - start, 2)
        Name = 'OneClassSVM' + '-' + self.dataname

        tn, fp, fn, tp, detection_rate, false_positive_rate = feedbackdata(
            y_test, y_pred)
        results = [
            tn, fp, fn, tp, detection_rate, false_positive_rate, totaltime
        ]
        self.adder(results, Name, alg)
Esempio n. 3
0
    def Ae(self):
        '''
        Function for Autoencoders
        :return:
        Returns results to be saved by the adder function
        '''

        alg = 1
        data = self.data
        train, valid, validB, testB = converter_1(data, AE=True)
        #Initial function to perform grid search
        global bestresults
        if self.iterator == 0:

            bestresults = Hyperparametertuning(train, valid, validB, testB)
            #bestresults = [1e-6, 'relu', 'Adam', 'mean_squared_error', 64,20]

        alg = 1

        train, valid, validB, testB = converter_1(data, AE=True)

        start = timeit.default_timer()
        loader = Autoen(train, valid, validB, testB)
        y_test, y_pred = loader.Ae(bestresults[0], bestresults[1],
                                   bestresults[2], bestresults[3],
                                   bestresults[4], bestresults[5])
        print(bestresults[0], bestresults[1], bestresults[2], bestresults[3],
              bestresults[4], bestresults[5])
        #y_test, y_pred= loader.Ae(1e-05,'relu', 'Adam', 'mean_squared_error', 1, 64)
        end = timeit.default_timer()
        totaltime = round(end - start, 2)
        opter, losser = 1, 2
        Name = 'AutoEncoder' + '-' + self.dataname
        tn, fp, fn, tp, detection_rate, false_positive_rate = feedbackdata(
            y_test, y_pred)
        results = [
            tn, fp, fn, tp, detection_rate, false_positive_rate, totaltime
        ]
        self.adder(results, Name, alg, opter, losser)

        print(self.iterator, "HEEEEEEEREEEEEEEEEEEEEE ITERATOR 22222")
Esempio n. 4
0
    def SVM(self):

        alg = 3
        data = self.data

        X_train, X_test, y_train, y_test = converter_1(data, SVM=True)

        start = timeit.default_timer()

        loader = SVM(X_train, X_test, y_train, y_test)
        y_test, y_pred = loader.svm()
        end = timeit.default_timer()
        totaltime = round(end - start, 2)

        Name = 'SVM' + '-' + self.dataname
        tn, fp, fn, tp, detection_rate, false_positive_rate = feedbackdata(
            y_test, y_pred)
        results = [
            tn, fp, fn, tp, detection_rate, false_positive_rate, totaltime
        ]

        self.adder(results, Name, alg)
Esempio n. 5
0
    def Iocsvm(self):
        '''
        Function for One Class SVM
        :return:
        Gives output to be saved by the adder function
        '''
        global bestresultssvm
        alg = 0
        data = self.data

        X_train, X_val, X_test, y_train, y_val, y_test = converter_1(
            data,
            onClassClassification=True,
            shuffle=False,
            test_size=0.25,
            validation_size=0.25)
        if self.iterator == 0:

            #pass
            bestresultssvm = SVMhyp(X_train, X_val, X_test, y_train, y_val,
                                    y_test)

        start = timeit.default_timer()
        loader = OneClassSVM(X_train, X_val, X_test, y_train, y_val, y_test,
                             bestresultssvm[0], bestresultssvm[1],
                             bestresultssvm[2])

        y_test, y_pred = loader.prediction()

        end = timeit.default_timer()
        totaltime = round(end - start, 2)
        Name = 'OneClassSVM' + '-' + self.dataname

        tn, fp, fn, tp, detection_rate, false_positive_rate = feedbackdata(
            y_test, y_pred)
        results = [
            tn, fp, fn, tp, detection_rate, false_positive_rate, totaltime
        ]
        self.adder(results, Name, alg, 0, 0)
Esempio n. 6
0
    def C_AE(self):
        '''
        Compressed Autoencoder function
        :return:
        Output to be saved by the adder function
        '''
        global opter
        global losser
        global bestresults
        alg = 2
        data = self.data
        train, validB, testB = converter_1(data, cAE=True)
        #GridSearch
        if self.iterator == 0:
            bestresults = [1e-5, 'relu', 'Adam', 'mean_absolute_error', 1, 83]
            #bestresults = C_Hyp(train, validB, testB)

        print(bestresults)

        start = timeit.default_timer()
        loader = compressing_autoencoder(train, validB, testB, bestresults[0],
                                         bestresults[1], bestresults[2],
                                         bestresults[3], bestresults[4],
                                         bestresults[5])

        loader.loading_data()
        y_test, y_pred = loader.test()
        end = timeit.default_timer()
        totaltime = round(end - start, 2)

        Name = 'Compressed_AutoEncoder' + '-' + self.dataname
        tn, fp, fn, tp, detection_rate, false_positive_rate = feedbackdata(
            y_test, y_pred)
        results = [
            tn, fp, fn, tp, detection_rate, false_positive_rate, totaltime
        ]
        self.adder(results, Name, alg, bestresults[3], bestresults[2])

        print(self.iterator, "HEEEEEEEREEEEEEEEEEEEEE ITERATOR 33333333333333")
Esempio n. 7
0
    def C_AE(self):

        alg = 2
        data = self.data
        train, validB, testB = converter_1(data, cAE=True)

        start = timeit.default_timer()
        loader = compressing_autoencoder(train, validB, testB)

        loader.loading_data()
        y_test, y_pred = loader.test()
        end = timeit.default_timer()
        totaltime = round(end - start, 2)

        Name = 'Compressed_AutoEncoder' + '-' + self.dataname
        tn, fp, fn, tp, detection_rate, false_positive_rate = feedbackdata(
            y_test, y_pred)
        results = [
            tn, fp, fn, tp, detection_rate, false_positive_rate, totaltime
        ]
        self.adder(results, Name, alg)

        print(self.iterator, "HEEEEEEEREEEEEEEEEEEEEE ITERATOR 33333333333333")
Esempio n. 8
0
    def Ae(self):
        global opter
        global losser
        # Initial function to perform grid search
        if self.iterator == 0:
            Optimizers = [
                'Adadelta', 'Adagrad', 'Adam', 'Adamax', 'Nadam', 'SGD'
            ]

            loss = [
                'binary_crossentropy', 'categorical_crossentropy',
                'cosine_similarity', 'mean_absolute_error',
                'mean_absolute_percentage_error', 'mean_squared_error',
                'mean_squared_logarithmic_error', 'poisson'
            ]
            test2 = 0

            for elements in range(len(Optimizers)):
                for elemento in range(len(loss)):
                    alg = 1
                    data = self.data
                    train, valid, validB, testB = converter_1(data, AE=True)

                    print(Optimizers[elements], 'Optimizer')
                    print(loss[elemento], ' loss')
                    loader = Autoen(train, valid, validB, testB,
                                    Optimizers[elements], loss[elemento])

                    y_test, y_pred = loader.Ae()

                    _, _, _, _, num, num2 = feedbackdata(y_test, y_pred)

                    if num2 <= 1:
                        num2 = 1
                    teste = num * (np.power(num, (1 / num2)))
                    if teste > test2:
                        opter = Optimizers[elements]
                        losser = loss[elemento]
                        test2 = teste

        print(opter, ' PRINTINGGGGG OPTIMIZZERRRR')
        print(losser, 'PRINTTINGG LOSSS')
        alg = 1
        data = self.data
        train, valid, validB, testB = converter_1(data, AE=True)

        start = timeit.default_timer()
        loader = Autoen(train, valid, validB, testB, opter, losser)

        y_test, y_pred = loader.Ae()
        end = timeit.default_timer()
        totaltime = round(end - start, 2)
        Name = 'AutoEncoder' + '-' + self.dataname
        tn, fp, fn, tp, detection_rate, false_positive_rate = feedbackdata(
            y_test, y_pred)
        results = [
            tn, fp, fn, tp, detection_rate, false_positive_rate, totaltime
        ]
        self.adder(results, Name, alg, opter, losser)

        print(self.iterator, "HEEEEEEEREEEEEEEEEEEEEE ITERATOR 22222")