def regression_linear_ridge_modular(fm_train=traindat, fm_test=testdat, label_train=label_traindat, tau=1e-6):

    from modshogun import RegressionLabels, RealFeatures
    from modshogun import LinearRidgeRegression

    rr = LinearRidgeRegression(tau, RealFeatures(traindat), RegressionLabels(label_train))
    rr.train()
    out = rr.apply(RealFeatures(fm_test)).get_labels()
    return out, rr
Esempio n. 2
0
def regression_linear_ridge_modular(fm_train=traindat,
                                    fm_test=testdat,
                                    label_train=label_traindat,
                                    tau=1e-6):

    from modshogun import RegressionLabels, RealFeatures
    from modshogun import LinearRidgeRegression

    rr = LinearRidgeRegression(tau, RealFeatures(traindat),
                               RegressionLabels(label_train))
    rr.train()
    out = rr.apply(RealFeatures(fm_test)).get_labels()
    return out, rr
Esempio n. 3
0
    lsr.train(RealFeatures(X.T))

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

evaluator = MeanSquaredError()

# apply on training data
mse_train = np.zeros(LeastAngleRegression.get_path_size())
for i in xrange(mse_train.shape[0]):
    LeastAngleRegression.switch_w(i)
    ypred = LeastAngleRegression.apply(RealFeatures(X.T))
    mse_train[i] = evaluator.evaluate(ypred, RegressionLabels(y))
ypred = lsr.apply(RealFeatures(X.T))
mse_train_lsr = evaluator.evaluate(ypred, RegressionLabels(y))

# apply on test data
mse_test = np.zeros(LeastAngleRegression.get_path_size())
for i in xrange(mse_test.shape[0]):
    LeastAngleRegression.switch_w(i)
    ypred = LeastAngleRegression.apply(RealFeatures(Xtest.T))
    mse_test[i] = evaluator.evaluate(ypred, RegressionLabels(y))
ypred = lsr.apply(RealFeatures(Xtest.T))
mse_test_lsr = evaluator.evaluate(ypred, RegressionLabels(y))

fig = plt.figure()
ax_path = fig.add_subplot(1, 2, 1)
plt.plot(xrange(path.shape[1]), path.T, ".-")
plt.legend(["%d" % (x + 1) for x in xrange(path.shape[0])])
Esempio n. 4
0
    lsr.train(RealFeatures(X.T))

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

evaluator = MeanSquaredError()

# apply on training data
mse_train = np.zeros(LeastAngleRegression.get_path_size())
for i in xrange(mse_train.shape[0]):
    LeastAngleRegression.switch_w(i)
    ypred = LeastAngleRegression.apply(RealFeatures(X.T))
    mse_train[i] = evaluator.evaluate(ypred, RegressionLabels(y))
ypred = lsr.apply(RealFeatures(X.T))
mse_train_lsr = evaluator.evaluate(ypred, RegressionLabels(y))

# apply on test data
mse_test = np.zeros(LeastAngleRegression.get_path_size())
for i in xrange(mse_test.shape[0]):
    LeastAngleRegression.switch_w(i)
    ypred = LeastAngleRegression.apply(RealFeatures(Xtest.T))
    mse_test[i] = evaluator.evaluate(ypred, RegressionLabels(y))
ypred = lsr.apply(RealFeatures(Xtest.T))
mse_test_lsr = evaluator.evaluate(ypred, RegressionLabels(y))

fig = plt.figure()
ax_path = fig.add_subplot(1, 2, 1)
plt.plot(xrange(path.shape[1]), path.T, '.-')
plt.legend(['%d' % (x + 1) for x in xrange(path.shape[0])])