Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi dimensional input Classification #612

Open
galfaroi opened this issue Mar 21, 2018 · 4 comments
Open

Multi dimensional input Classification #612

galfaroi opened this issue Mar 21, 2018 · 4 comments

Comments

@galfaroi
Copy link

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
Copy link
Member

mzwiessele commented Mar 21, 2018 via email

@galfaroi
Copy link
Author

galfaroi commented Mar 21, 2018

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
Copy link
Member

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

@galfaroi
Copy link
Author

galfaroi commented Mar 23, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants