Daniel Emaasit
Data Scientist @HaystaxTech, Ph.D. Candidate @UNLV, Bayesian Machine Learning Researcher, Organizer of Data Science Meetups. User of #PyMC3.
Daniel Emaasit
Data Scientist @ Haystax
import pymc3 as pm
# Instantiate a model
with pm.Model() as latent_gp_model:
# specify the priors
length_scale = pm.Gamma("length_scale", alpha = 2, beta = 1)
signal_variance = pm.HalfCauchy("signal_variance", beta = 5)
noise_variance = pm.HalfCauchy("noise_variance", beta = 5)
degrees_of_freedom = pm.Gamma("degrees_of_freedom", alpha = 2, beta = 0.1)
# specify the kernel function
cov = signal_variance**2 * pm.gp.cov.ExpQuad(1, length_scale)
# specify the mean function
mean_function = pm.gp.mean.Zero()
# specify the gp
gp = pm.gp.Latent(cov_func = cov)
# specify the prior over the latent function
f = gp.prior("f", X = X)
# specify the likelihood
obs = pm.StudentT("obs", mu = f, lam = 1/signal_variance, nu = degrees_of_freedom, observed = y)
# Perform Inference
with latent_gp_model:
posterior = pm.sample(draws = 100, njobs = 2)
# extend the model by adding the GP conditional distribution so as to predict at test data
with latent_gp_model:
f_pred = gp.conditional("f_pred", X_new)
# sample from the GP conditional posterior
with latent_gp_model:
posterior_pred = pm.sample_ppc(posterior, vars = [f_pred], samples = 200)
Build a model
Train a model
Prediction
from sklearn.gaussian_process import GaussianProcessRegressor()
model = GaussianProcessRegressor()
model.fit(X_train, y_train)
model.predict(X_test, y_test)
model.score(X_test, y_test)
model.save('path/to/saved/model')
Few lines of code
from pmlearn.gaussian_process import GaussianProcessRegressor()
# Instantiate a PyMC3 Gaussian process model
model = GaussianProcessRegressor()
# Fit using MCMC or Variational Inference
model.fit(X_train, y_train)
model.predict(X_test, y_test)
model.score(X_test, y_test)
model.save('path/to/saved/model')
Mimics Scikit-Learn
Slides: bit.ly/pymc-learn
By Daniel Emaasit
Pymc-Learn: Practical Probabilistic Machine Learning in Python
Data Scientist @HaystaxTech, Ph.D. Candidate @UNLV, Bayesian Machine Learning Researcher, Organizer of Data Science Meetups. User of #PyMC3.