I'm trying to validate an estimator which takes class arguments and seem to be getting multiple error messages:
def __init__(self, demo_param='demo_param', my_class=None):
self.demo_param = demo_param
self.my_class = my_class
import abc
import tensorflow as tf
class Likelihood:
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def predict(self, latent_val):
raise NotImplementedError("Subclass should implement this.")
class Gaussian(Likelihood):
def __init__(self, log_var=-2.0):
self.log_var = tf.Variable(log_var, name="log_theta")
def predict(self, latent_val):
return latent_val
like = Gaussian()
estimator = TemplateEstimator(demo_param='demo_param', my_class=like)
check_estimator(estimator)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-dd2c6598c00e> in <module>()
1 like = Gaussian()
2 estimator = TemplateEstimator(demo_param='demo_param', my_class=like)
----> 3 check_estimator(estimator)
/opt/conda/envs/py3/lib/python3.5/site-packages/sklearn/utils/estimator_checks.py in check_estimator(Estimator)
263 for check in _yield_all_checks(name, estimator):
264 try:
--> 265 check(name, estimator)
266 except SkipTest as message:
267 # the only SkipTest thrown currently results from not
/opt/conda/envs/py3/lib/python3.5/site-packages/sklearn/utils/testing.py in wrapper(*args, **kwargs)
289 with warnings.catch_warnings():
290 warnings.simplefilter("ignore", self.category)
--> 291 return fn(*args, **kwargs)
292
293 return wrapper
/opt/conda/envs/py3/lib/python3.5/site-packages/sklearn/utils/estimator_checks.py in check_estimators_dtypes(name, estimator_orig)
837
838 for X_train in [X_train_32, X_train_64, X_train_int_64, X_train_int_32]:
--> 839 estimator = clone(estimator_orig)
840 set_random_state(estimator, 1)
841 estimator.fit(X_train, y)
/opt/conda/envs/py3/lib/python3.5/site-packages/sklearn/base.py in clone(estimator, safe)
59 new_object_params = estimator.get_params(deep=False)
60 for name, param in six.iteritems(new_object_params):
---> 61 new_object_params[name] = clone(param, safe=False)
62 new_object = klass(**new_object_params)
63 params_set = new_object.get_params(deep=False)
/opt/conda/envs/py3/lib/python3.5/site-packages/sklearn/base.py in clone(estimator, safe)
50 elif not hasattr(estimator, 'get_params'):
51 if not safe:
---> 52 return copy.deepcopy(estimator)
53 else:
54 raise TypeError("Cannot clone object '%s' (type %s): "
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
180 raise Error(
181 "un(deep)copyable object of type %s" % cls)
--> 182 y = _reconstruct(x, rv, 1, memo)
183
184 # If is its own copy, don't memoize.
/opt/conda/envs/py3/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo)
295 if state is not None:
296 if deep:
--> 297 state = deepcopy(state, memo)
298 if hasattr(y, '__setstate__'):
299 y.__setstate__(state)
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
153 copier = _deepcopy_dispatch.get(cls)
154 if copier:
--> 155 y = copier(x, memo)
156 else:
157 try:
/opt/conda/envs/py3/lib/python3.5/copy.py in _deepcopy_dict(x, memo)
241 memo[id(x)] = y
242 for key, value in x.items():
--> 243 y[deepcopy(key, memo)] = deepcopy(value, memo)
244 return y
245 d[dict] = _deepcopy_dict
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
180 raise Error(
181 "un(deep)copyable object of type %s" % cls)
--> 182 y = _reconstruct(x, rv, 1, memo)
183
184 # If is its own copy, don't memoize.
/opt/conda/envs/py3/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo)
295 if state is not None:
296 if deep:
--> 297 state = deepcopy(state, memo)
298 if hasattr(y, '__setstate__'):
299 y.__setstate__(state)
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
153 copier = _deepcopy_dispatch.get(cls)
154 if copier:
--> 155 y = copier(x, memo)
156 else:
157 try:
/opt/conda/envs/py3/lib/python3.5/copy.py in _deepcopy_dict(x, memo)
241 memo[id(x)] = y
242 for key, value in x.items():
--> 243 y[deepcopy(key, memo)] = deepcopy(value, memo)
244 return y
245 d[dict] = _deepcopy_dict
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
180 raise Error(
181 "un(deep)copyable object of type %s" % cls)
--> 182 y = _reconstruct(x, rv, 1, memo)
183
184 # If is its own copy, don't memoize.
/opt/conda/envs/py3/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo)
295 if state is not None:
296 if deep:
--> 297 state = deepcopy(state, memo)
298 if hasattr(y, '__setstate__'):
299 y.__setstate__(state)
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
153 copier = _deepcopy_dispatch.get(cls)
154 if copier:
--> 155 y = copier(x, memo)
156 else:
157 try:
/opt/conda/envs/py3/lib/python3.5/copy.py in _deepcopy_dict(x, memo)
241 memo[id(x)] = y
242 for key, value in x.items():
--> 243 y[deepcopy(key, memo)] = deepcopy(value, memo)
244 return y
245 d[dict] = _deepcopy_dict
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
180 raise Error(
181 "un(deep)copyable object of type %s" % cls)
--> 182 y = _reconstruct(x, rv, 1, memo)
183
184 # If is its own copy, don't memoize.
/opt/conda/envs/py3/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo)
295 if state is not None:
296 if deep:
--> 297 state = deepcopy(state, memo)
298 if hasattr(y, '__setstate__'):
299 y.__setstate__(state)
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
153 copier = _deepcopy_dispatch.get(cls)
154 if copier:
--> 155 y = copier(x, memo)
156 else:
157 try:
/opt/conda/envs/py3/lib/python3.5/copy.py in _deepcopy_dict(x, memo)
241 memo[id(x)] = y
242 for key, value in x.items():
--> 243 y[deepcopy(key, memo)] = deepcopy(value, memo)
244 return y
245 d[dict] = _deepcopy_dict
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
180 raise Error(
181 "un(deep)copyable object of type %s" % cls)
--> 182 y = _reconstruct(x, rv, 1, memo)
183
184 # If is its own copy, don't memoize.
/opt/conda/envs/py3/lib/python3.5/copy.py in _reconstruct(x, info, deep, memo)
295 if state is not None:
296 if deep:
--> 297 state = deepcopy(state, memo)
298 if hasattr(y, '__setstate__'):
299 y.__setstate__(state)
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
153 copier = _deepcopy_dispatch.get(cls)
154 if copier:
--> 155 y = copier(x, memo)
156 else:
157 try:
/opt/conda/envs/py3/lib/python3.5/copy.py in _deepcopy_dict(x, memo)
241 memo[id(x)] = y
242 for key, value in x.items():
--> 243 y[deepcopy(key, memo)] = deepcopy(value, memo)
244 return y
245 d[dict] = _deepcopy_dict
/opt/conda/envs/py3/lib/python3.5/copy.py in deepcopy(x, memo, _nil)
172 reductor = getattr(x, "__reduce_ex__", None)
173 if reductor:
--> 174 rv = reductor(4)
175 else:
176 reductor = getattr(x, "__reduce__", None)
TypeError: can't pickle _thread.lock objects