Exemplo n.º 1
0
    def RunNBCShogun(q):
      totalTimer = Timer()

      Log.Info("Loading dataset", self.verbose)
      try:
        # Load train and test dataset.
        trainData = np.genfromtxt(self.dataset[0], delimiter=',')
        testData = np.genfromtxt(self.dataset[1], delimiter=',')

        # Labels are the last row of the training set.
        labels = MulticlassLabels(trainData[:, (trainData.shape[1] - 1)])

        with totalTimer:
          # Transform into features.
          trainFeat = RealFeatures(trainData[:,:-1].T)
          testFeat = RealFeatures(testData.T)

          # Create and train the classifier.
          nbc = GaussianNaiveBayes(trainFeat, labels)
          nbc.train()

          # Run Naive Bayes Classifier on the test dataset.
          nbc.apply(testFeat).get_labels()
      except Exception as e:
        q.put(-1)
        return -1

      time = totalTimer.ElapsedTime()
      q.put(time)
      return time
Exemplo n.º 2
0
        def RunNBCShogun(q):
            totalTimer = Timer()

            Log.Info("Loading dataset", self.verbose)
            try:
                # Load train and test dataset.
                trainData = np.genfromtxt(self.dataset[0], delimiter=',')
                testData = np.genfromtxt(self.dataset[1], delimiter=',')

                # Labels are the last row of the training set.
                labels = MulticlassLabels(trainData[:,
                                                    (trainData.shape[1] - 1)])

                with totalTimer:
                    # Transform into features.
                    trainFeat = RealFeatures(trainData[:, :-1].T)
                    testFeat = RealFeatures(testData.T)

                    # Create and train the classifier.
                    nbc = GaussianNaiveBayes(trainFeat, labels)
                    nbc.train()

                    # Run Naive Bayes Classifier on the test dataset.
                    nbc.apply(testFeat).get_labels()
            except Exception as e:
                q.put(-1)
                return -1

            time = totalTimer.ElapsedTime()
            q.put(time)
            return time
Exemplo n.º 3
0
def classifier_gaussiannaivebayes_modular (train_fname=traindat,test_fname=testdat,label_train_fname=label_traindat):
	from modshogun import RealFeatures, MulticlassLabels, GaussianNaiveBayes, CSVFile

	feats_train=RealFeatures(CSVFile(train_fname))
	feats_test=RealFeatures(CSVFile(test_fname))
	labels=MulticlassLabels(CSVFile(label_train_fname))

	gnb=GaussianNaiveBayes(feats_train, labels)
	gnb_train = gnb.train()
	output=gnb.apply(feats_test).get_labels()
	return gnb, gnb_train, output
Exemplo n.º 4
0
 def BuildModel(self, data, labels, options):
   nbc = GaussianNaiveBayes(data, labels)
   nbc.train()
   return nbc
Exemplo n.º 5
0
 def BuildModel(self, data, labels, options):
     nbc = GaussianNaiveBayes(data, labels)
     nbc.train()
     return nbc