mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-09 12:02:38 +02:00
New file, sparse one vs all classification
This commit is contained in:
parent
b2885e1882
commit
e6e8840ac1
2 changed files with 41 additions and 0 deletions
|
|
@ -20,3 +20,4 @@ from ss_mrd import SSMRD
|
||||||
from gp_kronecker_gaussian_regression import GPKroneckerGaussianRegression
|
from gp_kronecker_gaussian_regression import GPKroneckerGaussianRegression
|
||||||
from gp_var_gauss import GPVariationalGaussianApproximation
|
from gp_var_gauss import GPVariationalGaussianApproximation
|
||||||
from one_vs_all_classification import OneVsAllClassification
|
from one_vs_all_classification import OneVsAllClassification
|
||||||
|
from one_vs_all_sparse_classification import OneVsAllSparseClassification
|
||||||
|
|
|
||||||
40
GPy/models/one_vs_all_sparse_classification.py
Normal file
40
GPy/models/one_vs_all_sparse_classification.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
# Copyright (c) 2013, the GPy Authors (see AUTHORS.txt)
|
||||||
|
# Licensed under the BSD 3-clause license (see LICENSE.txt)
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import GPy
|
||||||
|
|
||||||
|
class OneVsAllSparseClassification(object):
|
||||||
|
"""
|
||||||
|
Gaussian Process classification: One vs all
|
||||||
|
|
||||||
|
This is a thin wrapper around the models.GPClassification class, with a set of sensible defaults
|
||||||
|
|
||||||
|
:param X: input observations
|
||||||
|
:param Y: observed values, can be None if likelihood is not None
|
||||||
|
:param kernel: a GPy kernel, defaults to rbf
|
||||||
|
|
||||||
|
.. Note:: Multiple independent outputs are not allowed
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, X, Y, kernel=None,Y_metadata=None,messages=True):
|
||||||
|
if kernel is None:
|
||||||
|
kernel = GPy.kern.RBF(X.shape[1])
|
||||||
|
|
||||||
|
likelihood = GPy.likelihoods.Bernoulli()
|
||||||
|
|
||||||
|
assert Y.shape[1] == 1, 'Y should be 1 column vector'
|
||||||
|
|
||||||
|
labels = np.unique(Y.flatten())
|
||||||
|
|
||||||
|
self.results = {}
|
||||||
|
for yj in labels:
|
||||||
|
print 'Class %s vs all' %yj
|
||||||
|
Ynew = Y.copy()
|
||||||
|
Ynew[Y.flatten()!=yj] = 0
|
||||||
|
Ynew[Y.flatten()==yj] = 1
|
||||||
|
|
||||||
|
m = GPy.models.SparseGPClassification(X,Ynew,kernel=kernel,Y_metadata=Y_metadata)
|
||||||
|
m.optimize(messages=messages)
|
||||||
|
self.results[yj] = m.predict(X)[0]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue