SheffieldML / GPy

Gaussian processes framework in python
BSD 3-Clause "New" or "Revised" License
1.99k stars 559 forks source link

Multi dimensional input Classification #612

Open galfaroi opened 6 years ago

galfaroi commented 6 years ago

Hi,

I am trying to do a multi dimensional input for a classification GP, it works very well for one dimension, but as soon I add another feature gives me a hashable error, I am pretty sure is something simple, but I cannot find a working example Thanks!

mzwiessele commented 6 years ago

Could you send your example, so we can see what is happening?

On 21. Mar 2018, at 09:45, German Alfaro notifications@github.com wrote:

Hi,

I am trying to do a multi dimensional input for a classification GP, it works very well for one dimension, but as soon I add another feature gives me a hashable error, I am pretty sure is something simple, but I cannot find a working example Thanks!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

galfaroi commented 6 years ago

Sure, N = X_train.shape[0] # number of data points D = X_train.shape[1] # number of features k = GPy.kern.RBF(input_dim=D, variance=7., lengthscale=0.2) model = GPy.models.GPClassification(X_train, y_train, kernel=k) ` Until there it works, but when I do m.predict, also tried "GPy.models.SparseGPClassification":

probs = model.predict(X_test) I got this error: TypeErrorTraceback (most recent call last)

in () ----> 1 probs = model.predict(X_test) /usr/local/lib/python2.7/dist-packages/GPy/core/gp.pyc in predict(self, Xnew, full_cov, Y_metadata, kern, likelihood, include_likelihood) 249 In particular in the GP class this method re-performs inference, recalculating the posterior and log marginal likelihood and gradients of the model 250 --> 251 .. warning:: 252 This method is not designed to be called manually, the framework is set up to automatically call this method upon changes to parameters, if you call 253 this method yourself, there may be unexpected consequences. /usr/local/lib/python2.7/dist-packages/GPy/core/gp.pyc in _raw_predict(self, Xnew, full_cov, kern) 216 self.X = X 217 self.link_parameter(self.X, index=index) --> 218 else: 219 index = self.X._parent_index_ 220 self.unlink_parameter(self.X) /usr/local/lib/python2.7/dist-packages/GPy/inference/latent_function_inference/posterior.pyc in _raw_predict(self, kern, Xnew, pred_var, full_cov) 244 psi0_star = kern.psi0(pred_var, Xnew) 245 psi1_star = kern.psi1(pred_var, Xnew) --> 246 psi2_star = kern.psi2n(pred_var, Xnew) 247 la = woodbury_vector 248 mu = np.dot(psi1_star, la) # TODO: dimensions? /usr/local/lib/python2.7/dist-packages/GPy/kern/src/kernel_slice_operations.pyc in wrap(self, X, X2, *a, **kw) 83 @wraps(f) 84 def wrap(self, X, X2 = None, *a, **kw): ---> 85 with _Slice_wrap(self, X, X2) as s: 86 ret = f(self, s.X, s.X2, *a, **kw) 87 return ret /usr/local/lib/python2.7/dist-packages/GPy/kern/src/kernel_slice_operations.pyc in __init__(self, k, X, X2, diag, ret_shape) 53 self.k._check_active_dims(X) 54 self.X = self.k._slice_X(X) ---> 55 self.X2 = self.k._slice_X(X2) if X2 is not None else X2 56 self.ret = True 57 else: in _slice_X(self, X) /usr/local/lib/python2.7/dist-packages/paramz/caching.pyc in g(obj, *args, **kw) 281 else: 282 cacher = cache[self.f] = Cacher(self.f, self.limit, self.ignore_args, self.force_kwargs, cacher_enabled=cache.caching_enabled) --> 283 return cacher(*args, **kw) 284 g.__name__ = f.__name__ 285 g.__doc__ = f.__doc__ /usr/local/lib/python2.7/dist-packages/paramz/caching.pyc in __call__(self, *args, **kw) 170 # print 'WARNING: '+self.operation.__name__ + ' not cacheable!' 171 # print [not (isinstance(b, Observable)) for b in inputs] --> 172 return self.operation(*args, **kw) 173 # 3&4: check whether this cache_id has been cached, then has it changed? 174 not_seen = not(cache_id in self.inputs_changed) /usr/local/lib/python2.7/dist-packages/GPy/kern/src/kern.pyc in _slice_X(self, X) 74 def to_dict(self): 75 raise NotImplementedError ---> 76 77 @staticmethod 78 def from_dict(input_dict): /usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in __getitem__(self, key) 2137 return self._getitem_multilevel(key) 2138 else: -> 2139 return self._getitem_column(key) 2140 2141 def _getitem_column(self, key): /usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _getitem_column(self, key) 2144 # get column 2145 if self.columns.is_unique: -> 2146 return self._get_item_cache(key) 2147 2148 # duplicate columns & possible reduce dimensionality /usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in _get_item_cache(self, item) 1838 """Return the cached item, item represents a label indexer.""" 1839 cache = self._item_cache -> 1840 res = cache.get(item) 1841 if res is None: 1842 values = self._data.get(item) TypeError: unhashable type
mzwiessele commented 6 years ago

Might X_test be a pandas array? Then try to convert it to a simple numpy array before giving it to the model.

galfaroi commented 6 years ago

Thank you I did and it works!

On Thu, Mar 22, 2018 at 1:25 PM, Max Zwiessele notifications@github.com wrote:

Might X_test be a pandas array? Then try to convert it to a simple numpy array before giving it to the model.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SheffieldML/GPy/issues/612#issuecomment-375445391, or mute the thread https://github.com/notifications/unsubscribe-auth/AF8zuOGDN6F0n9MzdSixdlLmIdKC_xuYks5thAiigaJpZM4SzLpF .