Пример #1
0
    def classify(runID, trainingSet, testingSet):
        [trainingFile,
         testingFile] = arffWriter.writeArffFiles(runID, trainingSet,
                                                  testingSet)

        # deep learning
        if config.DEEP_LEARNING_METHOD != -1:
            if config.DEEP_LEARNING_METHOD == 1:
                logistic_sgd_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 2:
                [trainingFile,
                 testingFile] = dA_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 3:
                mlp_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 4:
                SdA_2.runDL([trainingFile, testingFile])

        if config.NUM_MONITORED_SITES != -1:
            [accuracy, debugInfo] = ['NA', []]
            return [accuracy, debugInfo]
        '''
        return wekaAPI.execute( trainingFile,
                             testingFile,
                             "weka.Run weka.classifiers.functions.LibSVM",
                             ['-K','2', # RBF kernel
                              '-G','0.0000019073486328125', # Gamma
                              '-C','131072'] ) # Cost
        '''

        if config.CROSS_VALIDATION == 0:
            return wekaAPI.execute(
                trainingFile,
                testingFile,
                "weka.Run weka.classifiers.functions.LibSVM",
                [
                    '-K',
                    '2',  # RBF kernel
                    '-G',
                    '0.0000019073486328125',  # Gamma
                    ##May20 '-Z', # normalization 18 May 2015
                    '-C',
                    '131072'
                ])  # Cost
        else:
            file = Utils.joinTrainingTestingFiles(
                trainingFile, testingFile)  # join and shuffle
            return wekaAPI.executeCrossValidation(
                file,
                "weka.Run weka.classifiers.functions.LibSVM",
                [
                    '-x',
                    str(config.CROSS_VALIDATION),  # number of folds
                    '-K',
                    '2',  # RBF kernel
                    '-G',
                    '0.0000019073486328125',  # Gamma
                    ##May20 '-Z', # normalization 18 May 2015
                    '-C',
                    '131072'
                ])  # Cost
Пример #2
0
    def classify(runID, trainingSet, testingSet):
        [trainingFile,
         testingFile] = arffWriter.writeArffFiles(runID, trainingSet,
                                                  testingSet)
        # return wekaAPI.execute( trainingFile, testingFile, "weka.classifiers.bayes.NaiveBayes", ['-K'] )

        # deep learning
        if config.DEEP_LEARNING_METHOD != -1:
            #DLMethod = Utils.intToDL(config.DEEP_LEARNING_METHOD)
            #print 'Deep Learning Method: ' + DLMethod
            #[trainingFile, testingFile] = DLMethod.runDL([trainingFile, testingFile])
            #[trainingFile, testingFile] = dA_2.calcAE([trainingFile, testingFile])
            #SdA_2.calcSdA([trainingFile, testingFile])
            #logistic_sgd_2.calcLog_sgd([trainingFile, testingFile])
            if config.DEEP_LEARNING_METHOD == 1:
                logistic_sgd_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 2:
                [trainingFile,
                 testingFile] = dA_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 3:
                mlp_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 4:
                SdA_2.runDL([trainingFile, testingFile])

        if config.CROSS_VALIDATION == 0:
            return wekaAPI.execute(trainingFile, testingFile,
                                   "weka.classifiers.bayes.NaiveBayes", ['-K'])
        else:
            file = Utils.joinTrainingTestingFiles(
                trainingFile, testingFile)  # join and shuffle
            return wekaAPI.executeCrossValidation(
                file,
                "weka.classifiers.bayes.NaiveBayes",
                [
                    '-x',
                    str(config.CROSS_VALIDATION),  # number of folds
                    '-K'
                ])
    def classify(runID, trainingSet, testingSet):
        [trainingFile,
         testingFile] = arffWriter.writeArffFiles(runID, trainingSet,
                                                  testingSet)

        # deep learning (AE)
        if config.DEEP_LEARNING_METHOD != -1:
            #[trainingFile, testingFile] = dA_2.calcAE([trainingFile, testingFile]) # one layer dA
            #[trainingFile, testingFile] = dA_2.calcAE([trainingFile, testingFile]) # two layers dA
            #[trainingFile, testingFile] = dA_2.calcAE([trainingFile, testingFile])
            #SdA_2.calcSdA([trainingFile, testingFile])
            if config.DEEP_LEARNING_METHOD == 1:
                [trainingFile, testingFile
                 ] = logistic_sgd_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 2:
                [trainingFile,
                 testingFile] = dA_2.runDL([trainingFile, testingFile])
                [trainingFile,
                 testingFile] = dA_2.runDL([trainingFile, testingFile])
                #[trainingFile, testingFile] = dA_2.runDL([trainingFile, testingFile])
                #[trainingFile, testingFile] = dA_2.runDL([trainingFile, testingFile])
                #[trainingFile, testingFile] = dA_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 3:
                # DL classifier
                return mlp_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 4:
                return SdA_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 5:
                return mlp_3.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 6:
                return SdA_3.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 7:
                return LeNetConvPoolLayer_2.runDL([trainingFile, testingFile])

        return wekaAPI.execute(trainingFile, testingFile,
                               "weka.classifiers.bayes.NaiveBayes", ['-K'])
Пример #4
0
    def classify(runID, trainingSet, testingSet):
        [trainingFile,
         testingFile] = arffWriter.writeArffFiles(runID, trainingSet,
                                                  testingSet)
        [trainingFileOrig, testingFileOrig] = [trainingFile, testingFile]

        if config.NUM_MONITORED_SITES != -1:  #no need to classify as this is for generating openworld datasets. See the line above (arffWriter)
            [accuracy, debugInfo] = ['NA', []]
            return [accuracy, debugInfo]

        if config.n_components_PCA != 0:
            [trainingFile,
             testingFile] = Utils.calcPCA2([trainingFile, testingFile])

        if config.n_components_LDA != 0:
            [trainingFile,
             testingFile] = Utils.calcLDA4([trainingFile, testingFile])

        if config.n_components_QDA != 0:
            [trainingFile,
             testingFile] = Utils.calcQDA([trainingFile, testingFile])

        if config.lasso != 0:
            #[trainingFile,testingFile] = Utils.calcLasso3([trainingFile,testingFile])
            #[trainingFile,testingFile] = Utils.calcLogisticRegression([trainingFile,testingFile])
            Utils.calcLogisticRegression([trainingFile, testingFile])

        # deep learning
        if config.DEEP_LEARNING_METHOD != -1:
            #[trainingFile, testingFile] = dA_2.calcAE([trainingFile, testingFile]) # one layer dA
            #[trainingFile, testingFile] = dA_2.calcAE([trainingFile, testingFile]) # two layers dA
            #[trainingFile, testingFile] = dA_2.calcAE([trainingFile, testingFile])
            #SdA_2.calcSdA([trainingFile, testingFile])
            if config.DEEP_LEARNING_METHOD == 1:
                [trainingFile, testingFile
                 ] = logistic_sgd_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 2:
                [trainingFile,
                 testingFile] = dA_2.runDL([trainingFile, testingFile])
                [trainingFile,
                 testingFile] = dA_2.runDL([trainingFile, testingFile])
                #[trainingFile, testingFile] = dA_2.runDL([trainingFile, testingFile])
                #[trainingFile, testingFile] = dA_2.runDL([trainingFile, testingFile])
                #[trainingFile, testingFile] = dA_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 3:
                # DL classifier
                return mlp_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 4:
                return SdA_2.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 5:
                return mlp_3.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 6:
                return SdA_3.runDL([trainingFile, testingFile])
            elif config.DEEP_LEARNING_METHOD == 7:
                return LeNetConvPoolLayer_2.runDL([trainingFile, testingFile])

        #Utils.plotDensity([trainingFile,testingFile])
        #Utils.plot([trainingFile,testingFile])

        if config.OC_SVM == 0:  # multi-class svm
            if config.CROSS_VALIDATION == 0:
                #print 'WARNING: NB classifier with Bi-Di. ###########///////////XXXXXX???????? '
                #return wekaAPI.execute(trainingFile, testingFile, "weka.classifiers.bayes.NaiveBayes", ['-K'])

                return wekaAPI.execute(
                    trainingFile,
                    testingFile,
                    "weka.Run weka.classifiers.functions.LibSVM",
                    [
                        '-K',
                        '2',  # RBF kernel
                        '-G',
                        '0.0000019073486328125',  # Gamma
                        ##May20 '-Z', # normalization 18 May 2015
                        '-C',
                        '131072',  # Cost
                        #'-S','2', # one-class svm
                        '-B'
                    ])  # confidence

            else:
                file = Utils.joinTrainingTestingFiles(
                    trainingFile, testingFile)  # join and shuffle
                return wekaAPI.executeCrossValidation(
                    file,
                    "weka.Run weka.classifiers.functions.LibSVM",
                    [
                        '-x',
                        str(config.CROSS_VALIDATION),  # number of folds
                        '-K',
                        '2',  # RBF kernel
                        '-G',
                        '0.0000019073486328125',  # Gamma
                        ##May20 '-Z', # normalization 18 May 2015
                        '-C',
                        '131072',  # Cost
                        '-B'
                    ])  # confidence
        else:  # one-class svm
            if config.CROSS_VALIDATION == 0:
                print str(config.SVM_KERNEL)
                print str(config.OC_SVM_Nu)
                return wekaAPI.executeOneClassSVM(
                    trainingFile,
                    testingFile,
                    "weka.Run weka.classifiers.functions.LibSVM",
                    [
                        '-K',
                        str(config.SVM_KERNEL),
                        #'-K','2', # RBF kernel
                        #'-G','0.0000019073486328125', # Gamma
                        ##May20 '-Z', # normalization 18 May 2015
                        #'-C','131072', # Cost
                        #'-N','0.001', # nu
                        '-N',
                        str(config.OC_SVM_Nu),  # nu
                        '-S',
                        '2'
                    ])  #, # one-class svm
                #'-B'] )  # confidence
            else:
                file = Utils.joinTrainingTestingFiles(
                    trainingFile, testingFile)  # join and shuffle
                return wekaAPI.executeCrossValidation(
                    file,
                    "weka.Run weka.classifiers.functions.LibSVM",
                    [
                        '-x',
                        str(config.CROSS_VALIDATION),  # number of folds
                        '-K',
                        '2',  # RBF kernel
                        '-G',
                        '0.0000019073486328125',  # Gamma
                        ##May20 '-Z', # normalization 18 May 2015
                        '-C',
                        '131072',  # Cost
                        '-B'
                    ])  # confidence