コード例 #1
0
ファイル: ml_gp.py プロジェクト: pyongjoo/twitter-research
def testRegression():
    y = data.loadSVMLightTarget("../feature_set/synthetic.reg")

    # we are using pseudo index instead of the real feature set to use the
    # precomputed kernel.
    x = range(y.shape[0])
    dataset = zip(x, y)
    random.shuffle(dataset)

    # this precomputed kernel reads the index value and returns the covariance
    # matrix
    kernel = kernel_factory.precomputed("../feature_set/synthetic.kernel")

    for train, test in data.kFolds(dataset):
        x_train, y_train = zip(*train)
        x_train = np.atleast_2d(np.array(x_train)).T
        y_train = np.atleast_2d(np.array(y_train)).T

        reg = regress.GPRegressor(kernel)
        reg.fit(x_train, y_train)
        print "fitted"

        # test
        x_test, y_test = zip(*test)
        x_test = np.atleast_2d(np.array(x_test)).T
        y_test = np.atleast_2d(np.array(y_test)).T
        y_predict = reg.predict(x_test)

        print x_test.T
        print y_predict.T

        break
コード例 #2
0
ファイル: ml_gp.py プロジェクト: pyongjoo/twitter-research
def kernelAnalysis():
    y = data.loadSVMLightTarget("../feature_set/text.sreg")
    Cov = np.loadtxt("../feature_set/text.kernel")

    array = []

    for i in range(y.shape[0]):
        Cov[0][i]
コード例 #3
0
ファイル: ml_gp.py プロジェクト: pyongjoo/twitter-research
def regressAgeWithGP():
    y = data.loadSVMLightTarget("../feature_set/text.sreg")

    # we are using pseudo index instead of the real feature set to use the
    # precomputed kernel.
    x = range(y.shape[0])
    dataset = zip(x, y)
    random.shuffle(dataset)

    # this precomputed kernel reads the index value and returns the covariance
    # matrix
    for tau in [1e-3, 1e-2, 1e-1, 1, 1e1, 1e2, 1e3]:
        kernel = kernel_factory.precomputed("../feature_set/text.kernel", tau)

        rms_errors = []
        diviations = []

        for train, test in data.kFolds(dataset):
            x_train, y_train = zip(*train)
            x_train = np.atleast_2d(np.array(x_train)).T
            y_train = np.atleast_2d(np.array(y_train)).T

            reg = regress.GPRegressor(kernel)
            reg.fit(x_train, y_train)

            # test
            x_test, y_test = zip(*test)
            x_test = np.atleast_2d(np.array(x_test)).T
            y_test = np.atleast_2d(np.array(y_test)).T
            y_predict = reg.predict(x_test)

            rms_e = sqrt(np.mean((y_predict - y_test) ** 2))
            div_e = np.mean(np.absolute(y_predict - y_test))

            rms_errors.append(rms_e)
            diviations.append(div_e)

        print "tau:", tau
        print "rms error:", np.mean(np.array(rms_e))
        print "diviation:", np.mean(np.array(div_e))