Esempio n. 1
0
        def RunLARSShogun(q):
            totalTimer = Timer()

            # Load input dataset.
            try:
                Log.Info("Loading dataset", self.verbose)
                inputData = np.genfromtxt(self.dataset[0], delimiter=',')
                responsesData = np.genfromtxt(self.dataset[1], delimiter=',')
                inputFeat = RealFeatures(inputData.T)
                responsesFeat = RegressionLabels(responsesData)

                # Get all the parameters.
                lambda1 = re.search("-l (\d+)", options)
                lambda1 = 0.0 if not lambda1 else int(lambda1.group(1))

                with totalTimer:
                    # Perform LARS.
                    model = LeastAngleRegression(False)
                    model.set_max_l1_norm(lambda1)
                    model.set_labels(responsesFeat)
                    model.train(inputFeat)
                    model.get_w(model.get_path_size() - 1)
            except Exception as e:
                q.put(-1)
                return -1

            time = totalTimer.ElapsedTime()
            q.put(time)
            return time
Esempio n. 2
0
        def RunLASSOShogun(q):
            totalTimer = Timer()

            # Load input dataset.
            # If the dataset contains two files then the second file is the responses
            # file.
            try:
                Log.Info("Loading dataset", self.verbose)
                if len(self.dataset) == 2:
                    testSet = np.genfromtxt(self.dataset[1], delimiter=',')

                    # Get all the parameters.
                    lambda1 = re.search("-l (\d+)", options)
                    lambda1 = 0.0 if not lambda1 else int(lambda1.group(1))

                # Use the last row of the training set as the responses.
                X, y = SplitTrainData(self.dataset)

                with totalTimer:
                    model = LeastAngleRegression(lasso=True)
                    model.set_max_l1_norm(lambda1)
                    model.set_labels(RegressionLabels(y))
                    model.train(RealFeatures(X.T))

            except Exception as e:
                print(e)
                q.put(-1)
                return -1

            time = totalTimer.ElapsedTime()
            q.put(time)
            return time
Esempio n. 3
0
    def RunLARSShogun(q):
      totalTimer = Timer()

      # Load input dataset.
      try:
        Log.Info("Loading dataset", self.verbose)
        inputData = np.genfromtxt(self.dataset[0], delimiter=',')
        responsesData = np.genfromtxt(self.dataset[1], delimiter=',')
        inputFeat = RealFeatures(inputData.T)
        responsesFeat = RegressionLabels(responsesData)

        # Get all the parameters.
        lambda1 = None
        if "lambda1" in options:
          lambda1 = float(options.pop("lambda1"))

        if len(options) > 0:
          Log.Fatal("Unknown parameters: " + str(options))
          raise Exception("unknown parameters")

        with totalTimer:
          # Perform LARS.
          model = LeastAngleRegression(False)
          if lambda1:
            model.set_max_l1_norm(lambda1)
          model.set_labels(responsesFeat)
          model.train(inputFeat)
          model.get_w_for_var(model.get_path_size() - 1)
      except Exception as e:
        q.put(-1)
        return -1

      time = totalTimer.ElapsedTime()
      q.put(time)
      return time
Esempio n. 4
0
        def RunLASSOShogun():
            totalTimer = Timer()

            # Load input dataset.
            # If the dataset contains two files then the second file is the responses
            # file.
            try:
                Log.Info("Loading dataset", self.verbose)
                if len(self.dataset) >= 2:
                    testSet = np.genfromtxt(self.dataset[1], delimiter=',')

                # Get all the parameters.
                lambda1 = None
                if "lambda1" in options:
                    lambda1 = float(options.pop("lambda1"))

                if len(options) > 0:
                    Log.Fatal("Unknown parameters: " + str(options))
                    raise Exception("unknown parameters")

                # Use the last row of the training set as the responses.
                X, y = SplitTrainData(self.dataset)

                with totalTimer:
                    model = LeastAngleRegression(lasso=True)
                    if lambda1:
                        model.set_max_l1_norm(lambda1)
                    model.set_labels(RegressionLabels(y))
                    model.train(RealFeatures(X.T))

            except Exception as e:
                return -1

            return totalTimer.ElapsedTime()
Esempio n. 5
0
                                                2] + 0.5 * np.random.randn(n)

X = Xall[0:ntrain, :]
y = yall[0:ntrain]

Xtest = Xall[ntrain:, :]
ytest = yall[ntrain:]

# preprocess data
for i in xrange(p):
    X[:, i] -= np.mean(X[:, i])
    X[:, i] /= np.linalg.norm(X[:, i])
y -= np.mean(y)

# train LASSO
LeastAngleRegression = LeastAngleRegression()
LeastAngleRegression.set_labels(RegressionLabels(y))
LeastAngleRegression.train(RealFeatures(X.T))

# train ordinary LSR
if use_ridge:
    lsr = LinearRidgeRegression(0.01, RealFeatures(X.T), Labels(y))
    lsr.train()
else:
    lsr = LeastSquaresRegression()
    lsr.set_labels(RegressionLabels(y))
    lsr.train(RealFeatures(X.T))

# gather LASSO path
path = np.zeros((p, LeastAngleRegression.get_path_size()))
for i in xrange(path.shape[1]):