In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
import GPy

In [2]:
X = np.random.uniform(-3.,3.,(20,1))
Y = np.sin(X) + np.random.randn(20,1)*0.1

In [3]:
_ = plt.plot(X, Y, marker='.', linestyle='none')



In [4]:
kernel = GPy.kern.RBF(input_dim=1)

In [5]:
model = GPy.models.GPRegression(X, Y, kernel)

In [6]:
model.plot(plot_density=True)


Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f66c5565e50>
 /home/mattmcd/anaconda2/lib/python2.7/site-packages/matplotlib/figure.py:1999: UserWarning:This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.

In [7]:
model.optimize(messages=True)


Running L-BFGS-B (Scipy implementation) Code:
  runtime   i      f              |g|        
    00s03  0005   2.134324e+00   2.009626e-01 
    00s06  0010   2.119469e+00   4.861109e-05 
    00s12  0015   2.119428e+00   3.429012e-10 
    00s13  0017   2.119428e+00   3.018148e-13 
Runtime:     00s13
Optimization status: Converged

Out[7]:
<paramz.optimization.optimization.opt_lbfgsb at 0x7f66bb596390>

In [8]:
model.plot(plot_density=True)


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f66bb5a6110>

In [9]:
model


Out[9]:

Model: GP regression
Objective: 2.11942761662
Number of Parameters: 3
Number of Optimization Parameters: 3
Updates: True

GP_regression. valueconstraintspriors
rbf.variance 0.593731925545 +ve
rbf.lengthscale 1.54500031436 +ve
Gaussian_noise.variance0.0280885408809 +ve

In [10]:
help(model.predict)


Help on method predict in module GPy.core.gp:

predict(self, Xnew, full_cov=False, Y_metadata=None, kern=None, likelihood=None, include_likelihood=True) method of GPy.models.gp_regression.GPRegression instance
    Predict the function(s) at the new point(s) Xnew. This includes the likelihood
    variance added to the predicted underlying function (usually referred to as f).
    
    In order to predict without adding in the likelihood give
    `include_likelihood=False`, or refer to self.predict_noiseless().
    
    :param Xnew: The points at which to make a prediction
    :type Xnew: np.ndarray (Nnew x self.input_dim)
    :param full_cov: whether to return the full covariance matrix, or just
                     the diagonal
    :type full_cov: bool
    :param Y_metadata: metadata about the predicting point to pass to the likelihood
    :param kern: The kernel to use for prediction (defaults to the model
                 kern). this is useful for examining e.g. subprocesses.
    :param bool include_likelihood: Whether or not to add likelihood noise to the predicted underlying latent function f.
    
    :returns: (mean, var):
        mean: posterior mean, a Numpy array, Nnew x self.input_dim
        var: posterior variance, a Numpy array, Nnew x 1 if full_cov=False, Nnew x Nnew otherwise
    
       If full_cov and self.input_dim > 1, the return shape of var is Nnew x Nnew x self.input_dim. If self.input_dim == 1, the return shape is Nnew x Nnew.
       This is to allow for different normalizations of the output dimensions.
    
    Note: If you want the predictive quantiles (e.g. 95% confidence interval) use :py:func:"~GPy.core.gp.GP.predict_quantiles".


In [11]:
model.predict(np.array([4.0]).reshape(-1,1))


Out[11]:
(array([[-0.32605298]]), array([[ 0.21352971]]))

In [12]:
help(GPy.core.gp.GP.predict_quantiles)


Help on method predict_quantiles in module GPy.core.gp:

predict_quantiles(self, X, quantiles=(2.5, 97.5), Y_metadata=None, kern=None, likelihood=None) unbound GPy.core.gp.GP method
    Get the predictive quantiles around the prediction at X
    
    :param X: The points at which to make a prediction
    :type X: np.ndarray (Xnew x self.input_dim)
    :param quantiles: tuple of quantiles, default is (2.5, 97.5) which is the 95% interval
    :type quantiles: tuple
    :param kern: optional kernel to use for prediction
    :type predict_kw: dict
    :returns: list of quantiles for each X and predictive quantiles for interval combination
    :rtype: [np.ndarray (Xnew x self.output_dim), np.ndarray (Xnew x self.output_dim)]


In [13]:
model.predict_quantiles(np.array([4.0]).reshape(-1,1), quantiles=(2.5, 97.5))


Out[13]:
[array([[-1.23173813]]), array([[ 0.57963216]])]

In [ ]: