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

AttributeError: 'AutoSklearnClassifier' object has no attribute 'load_models' #1061

Closed
snthibaud opened this issue Jan 19, 2021 · 7 comments
Closed

Comments

@snthibaud
Copy link

Describe the bug

AttributeError: 'AutoSklearnClassifier' object has no attribute 'load_models'
when trying to score the model with cross validator.

To Reproduce

Run the following code with some dataset in X and y:

from autosklearn.classification import AutoSklearnClassifier
from autosklearn.metrics import average_precision

if __name__ == '__main__':
    clf = AutoSklearnClassifier(metric=average_precision, memory_limit=192*1024)
    clf.fit(X, y)
    cross_validate(clf, X, y, n_jobs=-1, scoring="average_precision")["test_score"].mean()

Expected behavior

I would expect a number to result from it.

Actual behavior, stacktrace or logfile

Stacktrace:

AttributeError                            Traceback (most recent call last)
<ipython-input-29-8d5e33cc8853> in <module>
----> 1 cross_validate(clf, Xfloat, y, n_jobs=-1, scoring="average_precision")["test_score"].mean()

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs)
     61             extra_args = len(args) - len(all_args)
     62             if extra_args <= 0:
---> 63                 return f(*args, **kwargs)
     64 
     65             # extra_args > 0

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/model_selection/_validation.py in cross_validate(estimator, X, y, groups, scoring, cv, n_jobs, verbose, fit_params, pre_dispatch, return_train_score, return_estimator, error_score)
    244     parallel = Parallel(n_jobs=n_jobs, verbose=verbose,
    245                         pre_dispatch=pre_dispatch)
--> 246     results = parallel(
    247         delayed(_fit_and_score)(
    248             clone(estimator), X, y, scorers, train, test, verbose, None,

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/joblib/parallel.py in __call__(self, iterable)
   1039             # remaining jobs.
   1040             self._iterating = False
-> 1041             if self.dispatch_one_batch(iterator):
   1042                 self._iterating = self._original_iterator is not None
   1043 

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/joblib/parallel.py in dispatch_one_batch(self, iterator)
    829                 big_batch_size = batch_size * n_jobs
    830 
--> 831                 islice = list(itertools.islice(iterator, big_batch_size))
    832                 if len(islice) == 0:
    833                     return False

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/model_selection/_validation.py in <genexpr>(.0)
    246     results = parallel(
    247         delayed(_fit_and_score)(
--> 248             clone(estimator), X, y, scorers, train, test, verbose, None,
    249             fit_params, return_train_score=return_train_score,
    250             return_times=True, return_estimator=return_estimator,

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs)
     61             extra_args = len(args) - len(all_args)
     62             if extra_args <= 0:
---> 63                 return f(*args, **kwargs)
     64 
     65             # extra_args > 0

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/base.py in clone(estimator, safe)
     72 
     73     klass = estimator.__class__
---> 74     new_object_params = estimator.get_params(deep=False)
     75     for name, param in new_object_params.items():
     76         new_object_params[name] = clone(param, safe=False)

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/base.py in get_params(self, deep)
    193         out = dict()
    194         for key in self._get_param_names():
--> 195             value = getattr(self, key)
    196             if deep and hasattr(value, 'get_params'):
    197                 deep_items = value.get_params().items()

AttributeError: 'AutoSklearnClassifier' object has no attribute 'load_models'

Environment and installation:

Please give details about your installation:

  • OS: AWS Linux
  • Using a Conda environment
  • Python: 3.8
  • Auto-sklearn version: 0.12.1
@snthibaud
Copy link
Author

This issue also occurred when using the 'refit' method on the experimental AutoSklearn2Classifier:

/home/ec2-user/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/linear_model/_stochastic_gradient.py:574: ConvergenceWarning: Maximum number of iteration reached before convergence. Consider increasing max_iter to improve the fit.
  warnings.warn("Maximum number of iteration reached before "
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/base.py in _repr_mimebundle_(self, **kwargs)
    462     def _repr_mimebundle_(self, **kwargs):
    463         """Mime bundle used by jupyter kernels to display estimator"""
--> 464         output = {"text/plain": repr(self)}
    465         if get_config()["display"] == 'diagram':
    466             output["text/html"] = estimator_html_repr(self)

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/base.py in __repr__(self, N_CHAR_MAX)
    258             n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
    259 
--> 260         repr_ = pp.pformat(self)
    261 
    262         # Use bruteforce ellipsis when there are a lot of non-blank characters

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/pprint.py in pformat(self, object)
    151     def pformat(self, object):
    152         sio = _StringIO()
--> 153         self._format(object, sio, 0, 0, {}, 0)
    154         return sio.getvalue()
    155 

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/pprint.py in _format(self, object, stream, indent, allowance, context, level)
    168             self._readable = False
    169             return
--> 170         rep = self._repr(object, context, level)
    171         max_width = self._width - indent - allowance
    172         if len(rep) > max_width:

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/pprint.py in _repr(self, object, context, level)
    402 
    403     def _repr(self, object, context, level):
--> 404         repr, readable, recursive = self.format(object, context.copy(),
    405                                                 self._depth, level)
    406         if not readable:

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
    178 
    179     def format(self, object, context, maxlevels, level):
--> 180         return _safe_repr(object, context, maxlevels, level,
    181                           changed_only=self._changed_only)
    182 

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
    423         recursive = False
    424         if changed_only:
--> 425             params = _changed_params(object)
    426         else:
    427             params = object.get_params(deep=False)

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
     89     estimator with non-default values."""
     90 
---> 91     params = estimator.get_params(deep=False)
     92     init_func = getattr(estimator.__init__, 'deprecated_original',
     93                         estimator.__init__)

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/base.py in get_params(self, deep)
    193         out = dict()
    194         for key in self._get_param_names():
--> 195             value = getattr(self, key)
    196             if deep and hasattr(value, 'get_params'):
    197                 deep_items = value.get_params().items()

AttributeError: 'AutoSklearn2Classifier' object has no attribute 'load_models'
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    392                         if cls is not object \
    393                                 and callable(cls.__dict__.get('__repr__')):
--> 394                             return _repr_pprint(obj, self, cycle)
    395 
    396             return _default_pprint(obj, self, cycle)

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    698     """A pprint that just redirects to the normal repr function."""
    699     # Find newlines and replace them with p.break_()
--> 700     output = repr(obj)
    701     lines = output.splitlines()
    702     with p.group():

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/base.py in __repr__(self, N_CHAR_MAX)
    258             n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
    259 
--> 260         repr_ = pp.pformat(self)
    261 
    262         # Use bruteforce ellipsis when there are a lot of non-blank characters

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/pprint.py in pformat(self, object)
    151     def pformat(self, object):
    152         sio = _StringIO()
--> 153         self._format(object, sio, 0, 0, {}, 0)
    154         return sio.getvalue()
    155 

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/pprint.py in _format(self, object, stream, indent, allowance, context, level)
    168             self._readable = False
    169             return
--> 170         rep = self._repr(object, context, level)
    171         max_width = self._width - indent - allowance
    172         if len(rep) > max_width:

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/pprint.py in _repr(self, object, context, level)
    402 
    403     def _repr(self, object, context, level):
--> 404         repr, readable, recursive = self.format(object, context.copy(),
    405                                                 self._depth, level)
    406         if not readable:

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
    178 
    179     def format(self, object, context, maxlevels, level):
--> 180         return _safe_repr(object, context, maxlevels, level,
    181                           changed_only=self._changed_only)
    182 

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
    423         recursive = False
    424         if changed_only:
--> 425             params = _changed_params(object)
    426         else:
    427             params = object.get_params(deep=False)

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
     89     estimator with non-default values."""
     90 
---> 91     params = estimator.get_params(deep=False)
     92     init_func = getattr(estimator.__init__, 'deprecated_original',
     93                         estimator.__init__)

~/SageMaker/custom-miniconda/miniconda/envs/python_38/lib/python3.8/site-packages/sklearn/base.py in get_params(self, deep)
    193         out = dict()
    194         for key in self._get_param_names():
--> 195             value = getattr(self, key)
    196             if deep and hasattr(value, 'get_params'):
    197                 deep_items = value.get_params().items()

AttributeError: 'AutoSklearn2Classifier' object has no attribute 'load_models'

@jiayiwus1x
Copy link

jiayiwus1x commented Jan 20, 2021

Experience the same issue with resampling strategy = 'cv' instead of default:
code:

automl = autosklearn.classification.AutoSklearnClassifier(ensemble_size=1, initial_configurations_via_metalearning=0, output_folder='results/',
                                                          resampling_strategy = 'cv', ensemble_memory_limit=4096,
                                                          resampling_strategy_arguments= {'cv': {'folds': 5}})
automl.fit(X_train, y_train)

error:

AttributeError                            Traceback (most recent call last)
~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/base.py in _repr_mimebundle_(self, **kwargs)
    462     def _repr_mimebundle_(self, **kwargs):
    463         """Mime bundle used by jupyter kernels to display estimator"""
--> 464         output = {"text/plain": repr(self)}
    465         if get_config()["display"] == 'diagram':
    466             output["text/html"] = estimator_html_repr(self)

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/base.py in __repr__(self, N_CHAR_MAX)
    258             n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
    259 
--> 260         repr_ = pp.pformat(self)
    261 
    262         # Use bruteforce ellipsis when there are a lot of non-blank characters

~/.conda/envs/tf2-gpu/lib/python3.7/pprint.py in pformat(self, object)
    142     def pformat(self, object):
    143         sio = _StringIO()
--> 144         self._format(object, sio, 0, 0, {}, 0)
    145         return sio.getvalue()
    146 

~/.conda/envs/tf2-gpu/lib/python3.7/pprint.py in _format(self, object, stream, indent, allowance, context, level)
    159             self._readable = False
    160             return
--> 161         rep = self._repr(object, context, level)
    162         max_width = self._width - indent - allowance
    163         if len(rep) > max_width:

~/.conda/envs/tf2-gpu/lib/python3.7/pprint.py in _repr(self, object, context, level)
    391     def _repr(self, object, context, level):
    392         repr, readable, recursive = self.format(object, context.copy(),
--> 393                                                 self._depth, level)
    394         if not readable:
    395             self._readable = False

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
    179     def format(self, object, context, maxlevels, level):
    180         return _safe_repr(object, context, maxlevels, level,
--> 181                           changed_only=self._changed_only)
    182 
    183     def _pprint_estimator(self, object, stream, indent, allowance, context,

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
    423         recursive = False
    424         if changed_only:
--> 425             params = _changed_params(object)
    426         else:
    427             params = object.get_params(deep=False)

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
     89     estimator with non-default values."""
     90 
---> 91     params = estimator.get_params(deep=False)
     92     init_func = getattr(estimator.__init__, 'deprecated_original',
     93                         estimator.__init__)

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/base.py in get_params(self, deep)
    193         out = dict()
    194         for key in self._get_param_names():
--> 195             value = getattr(self, key)
    196             if deep and hasattr(value, 'get_params'):
    197                 deep_items = value.get_params().items()

AttributeError: 'AutoSklearnClassifier' object has no attribute 'load_models'

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    392                         if cls is not object \
    393                                 and callable(cls.__dict__.get('__repr__')):
--> 394                             return _repr_pprint(obj, self, cycle)
    395 
    396             return _default_pprint(obj, self, cycle)

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    698     """A pprint that just redirects to the normal repr function."""
    699     # Find newlines and replace them with p.break_()
--> 700     output = repr(obj)
    701     lines = output.splitlines()
    702     with p.group():

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/base.py in __repr__(self, N_CHAR_MAX)
    258             n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
    259 
--> 260         repr_ = pp.pformat(self)
    261 
    262         # Use bruteforce ellipsis when there are a lot of non-blank characters

~/.conda/envs/tf2-gpu/lib/python3.7/pprint.py in pformat(self, object)
    142     def pformat(self, object):
    143         sio = _StringIO()
--> 144         self._format(object, sio, 0, 0, {}, 0)
    145         return sio.getvalue()
    146 

~/.conda/envs/tf2-gpu/lib/python3.7/pprint.py in _format(self, object, stream, indent, allowance, context, level)
    159             self._readable = False
    160             return
--> 161         rep = self._repr(object, context, level)
    162         max_width = self._width - indent - allowance
    163         if len(rep) > max_width:

~/.conda/envs/tf2-gpu/lib/python3.7/pprint.py in _repr(self, object, context, level)
    391     def _repr(self, object, context, level):
    392         repr, readable, recursive = self.format(object, context.copy(),
--> 393                                                 self._depth, level)
    394         if not readable:
    395             self._readable = False

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
    179     def format(self, object, context, maxlevels, level):
    180         return _safe_repr(object, context, maxlevels, level,
--> 181                           changed_only=self._changed_only)
    182 
    183     def _pprint_estimator(self, object, stream, indent, allowance, context,

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
    423         recursive = False
    424         if changed_only:
--> 425             params = _changed_params(object)
    426         else:
    427             params = object.get_params(deep=False)

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
     89     estimator with non-default values."""
     90 
---> 91     params = estimator.get_params(deep=False)
     92     init_func = getattr(estimator.__init__, 'deprecated_original',
     93                         estimator.__init__)

~/.conda/envs/tf2-gpu/lib/python3.7/site-packages/sklearn/base.py in get_params(self, deep)
    193         out = dict()
    194         for key in self._get_param_names():
--> 195             value = getattr(self, key)
    196             if deep and hasattr(value, 'get_params'):
    197                 deep_items = value.get_params().items()

AttributeError: 'AutoSklearnClassifier' object has no attribute 'load_models'

@goyetc
Copy link

goyetc commented Jan 20, 2021

Experiencing same issue.
numpy 1.16.1
numpydoc 0.9.2
auto-sklearn 0.12.1
scikit-learn 0.24.1

auto_cls = autosklearn.classification.AutoSklearnClassifier(time_left_for_this_task=60, per_run_time_limit=15)
`print('model training in progress..')
auto_cls.fit(X_train.values, y_train.values)
model training in progress..

AttributeError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/IPython/core/formatters.py in call(self, obj, include, exclude)
968
969 if method is not None:
--> 970 return method(include=include, exclude=exclude)
971 return None
972 else:

/opt/conda/lib/python3.6/site-packages/sklearn/base.py in repr_mimebundle(self, **kwargs)
462 def repr_mimebundle(self, **kwargs):
463 """Mime bundle used by jupyter kernels to display estimator"""
--> 464 output = {"text/plain": repr(self)}
465 if get_config()["display"] == 'diagram':
466 output["text/html"] = estimator_html_repr(self)

/opt/conda/lib/python3.6/site-packages/sklearn/base.py in repr(self, N_CHAR_MAX)
258 n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
259
--> 260 repr_ = pp.pformat(self)
261
262 # Use bruteforce ellipsis when there are a lot of non-blank characters

/opt/conda/lib/python3.6/pprint.py in pformat(self, object)
142 def pformat(self, object):
143 sio = _StringIO()
--> 144 self._format(object, sio, 0, 0, {}, 0)
145 return sio.getvalue()
146

/opt/conda/lib/python3.6/pprint.py in _format(self, object, stream, indent, allowance, context, level)
159 self._readable = False
160 return
--> 161 rep = self._repr(object, context, level)
162 max_width = self._width - indent - allowance
163 if len(rep) > max_width:

/opt/conda/lib/python3.6/pprint.py in _repr(self, object, context, level)
391 def _repr(self, object, context, level):
392 repr, readable, recursive = self.format(object, context.copy(),
--> 393 self._depth, level)
394 if not readable:
395 self._readable = False

/opt/conda/lib/python3.6/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
179 def format(self, object, context, maxlevels, level):
180 return _safe_repr(object, context, maxlevels, level,
--> 181 changed_only=self._changed_only)
182
183 def _pprint_estimator(self, object, stream, indent, allowance, context,

/opt/conda/lib/python3.6/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
423 recursive = False
424 if changed_only:
--> 425 params = _changed_params(object)
426 else:
427 params = object.get_params(deep=False)

/opt/conda/lib/python3.6/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
89 estimator with non-default values."""
90
---> 91 params = estimator.get_params(deep=False)
92 init_func = getattr(estimator.init, 'deprecated_original',
93 estimator.init)

/opt/conda/lib/python3.6/site-packages/sklearn/base.py in get_params(self, deep)
193 out = dict()
194 for key in self._get_param_names():
--> 195 value = getattr(self, key)
196 if deep and hasattr(value, 'get_params'):
197 deep_items = value.get_params().items()

AttributeError: 'AutoSklearnClassifier' object has no attribute 'load_models'

AttributeError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/IPython/core/formatters.py in call(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
--> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()

/opt/conda/lib/python3.6/site-packages/IPython/lib/pretty.py in pretty(self, obj)
392 if cls is not object
393 and callable(cls.dict.get('repr')):
--> 394 return _repr_pprint(obj, self, cycle)
395
396 return _default_pprint(obj, self, cycle)

/opt/conda/lib/python3.6/site-packages/IPython/lib/pretty.py in repr_pprint(obj, p, cycle)
698 """A pprint that just redirects to the normal repr function."""
699 # Find newlines and replace them with p.break
()
--> 700 output = repr(obj)
701 lines = output.splitlines()
702 with p.group():

/opt/conda/lib/python3.6/site-packages/sklearn/base.py in repr(self, N_CHAR_MAX)
258 n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
259
--> 260 repr_ = pp.pformat(self)
261
262 # Use bruteforce ellipsis when there are a lot of non-blank characters

/opt/conda/lib/python3.6/pprint.py in pformat(self, object)
142 def pformat(self, object):
143 sio = _StringIO()
--> 144 self._format(object, sio, 0, 0, {}, 0)
145 return sio.getvalue()
146

/opt/conda/lib/python3.6/pprint.py in _format(self, object, stream, indent, allowance, context, level)
159 self._readable = False
160 return
--> 161 rep = self._repr(object, context, level)
162 max_width = self._width - indent - allowance
163 if len(rep) > max_width:

/opt/conda/lib/python3.6/pprint.py in _repr(self, object, context, level)
391 def _repr(self, object, context, level):
392 repr, readable, recursive = self.format(object, context.copy(),
--> 393 self._depth, level)
394 if not readable:
395 self._readable = False

/opt/conda/lib/python3.6/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
179 def format(self, object, context, maxlevels, level):
180 return _safe_repr(object, context, maxlevels, level,
--> 181 changed_only=self._changed_only)
182
183 def _pprint_estimator(self, object, stream, indent, allowance, context,

/opt/conda/lib/python3.6/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
423 recursive = False
424 if changed_only:
--> 425 params = _changed_params(object)
426 else:
427 params = object.get_params(deep=False)

/opt/conda/lib/python3.6/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
89 estimator with non-default values."""
90
---> 91 params = estimator.get_params(deep=False)
92 init_func = getattr(estimator.init, 'deprecated_original',
93 estimator.init)

/opt/conda/lib/python3.6/site-packages/sklearn/base.py in get_params(self, deep)
193 out = dict()
194 for key in self._get_param_names():
--> 195 value = getattr(self, key)
196 if deep and hasattr(value, 'get_params'):
197 deep_items = value.get_params().items()

AttributeError: 'AutoSklearnClassifier' object has no attribute 'load_models'`

This was referenced Jan 21, 2021
@ybdong919
Copy link

Meet same problem:

automl = autosklearn.classification.AutoSklearnClassifier(time_left_for_this_task=120)
automl.fit(x_train,y_train, dataset_name='howells')
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.6/dist-packages/sklearn/base.py", line 260, in repr
repr_ = pp.pformat(self)
File "/usr/lib/python3.6/pprint.py", line 144, in pformat
self._format(object, sio, 0, 0, {}, 0)
File "/usr/lib/python3.6/pprint.py", line 161, in _format
rep = self._repr(object, context, level)
File "/usr/lib/python3.6/pprint.py", line 393, in _repr
self._depth, level)
File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/_pprint.py", line 181, in format
changed_only=self._changed_only)
File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/_pprint.py", line 425, in _safe_repr
params = _changed_params(object)
File "/usr/local/lib/python3.6/dist-packages/sklearn/utils/_pprint.py", line 91, in _changed_params
params = estimator.get_params(deep=False)
File "/usr/local/lib/python3.6/dist-packages/sklearn/base.py", line 195, in get_params
value = getattr(self, key)
AttributeError: 'AutoSklearnClassifier' object has no attribute 'load_models'

@juliuskittler
Copy link

I am also getting this AttributeError but with the AutoSklearnRegressor: AttributeError: 'AutoSklearnRegressor' object has no attribute 'load_models'.

Code

automl = autosklearn.regression.AutoSklearnRegressor(
    time_left_for_this_task=180,
    per_run_time_limit=30,
    tmp_folder='/tmp/autosklearn_regression_example_tmp',
    output_folder='/tmp/autosklearn_regression_example_out',
    delete_output_folder_after_terminate=False,
    delete_tmp_folder_after_terminate=False
)
automl.fit(X_tr, y_tr, dataset_name=DATA_INPUT_PATH_TR.split("/")[-1].split(".")[0])

Error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/base.py in _repr_mimebundle_(self, **kwargs)
    462     def _repr_mimebundle_(self, **kwargs):
    463         """Mime bundle used by jupyter kernels to display estimator"""
--> 464         output = {"text/plain": repr(self)}
    465         if get_config()["display"] == 'diagram':
    466             output["text/html"] = estimator_html_repr(self)

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/base.py in __repr__(self, N_CHAR_MAX)
    258             n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
    259 
--> 260         repr_ = pp.pformat(self)
    261 
    262         # Use bruteforce ellipsis when there are a lot of non-blank characters

~/anaconda3/envs/auto-ml/lib/python3.8/pprint.py in pformat(self, object)
    151     def pformat(self, object):
    152         sio = _StringIO()
--> 153         self._format(object, sio, 0, 0, {}, 0)
    154         return sio.getvalue()
    155 

~/anaconda3/envs/auto-ml/lib/python3.8/pprint.py in _format(self, object, stream, indent, allowance, context, level)
    168             self._readable = False
    169             return
--> 170         rep = self._repr(object, context, level)
    171         max_width = self._width - indent - allowance
    172         if len(rep) > max_width:

~/anaconda3/envs/auto-ml/lib/python3.8/pprint.py in _repr(self, object, context, level)
    402 
    403     def _repr(self, object, context, level):
--> 404         repr, readable, recursive = self.format(object, context.copy(),
    405                                                 self._depth, level)
    406         if not readable:

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
    178 
    179     def format(self, object, context, maxlevels, level):
--> 180         return _safe_repr(object, context, maxlevels, level,
    181                           changed_only=self._changed_only)
    182 

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
    423         recursive = False
    424         if changed_only:
--> 425             params = _changed_params(object)
    426         else:
    427             params = object.get_params(deep=False)

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
     89     estimator with non-default values."""
     90 
---> 91     params = estimator.get_params(deep=False)
     92     init_func = getattr(estimator.__init__, 'deprecated_original',
     93                         estimator.__init__)

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/base.py in get_params(self, deep)
    193         out = dict()
    194         for key in self._get_param_names():
--> 195             value = getattr(self, key)
    196             if deep and hasattr(value, 'get_params'):
    197                 deep_items = value.get_params().items()

AttributeError: 'AutoSklearnRegressor' object has no attribute 'load_models'

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    392                         if cls is not object \
    393                                 and callable(cls.__dict__.get('__repr__')):
--> 394                             return _repr_pprint(obj, self, cycle)
    395 
    396             return _default_pprint(obj, self, cycle)

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    698     """A pprint that just redirects to the normal repr function."""
    699     # Find newlines and replace them with p.break_()
--> 700     output = repr(obj)
    701     lines = output.splitlines()
    702     with p.group():

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/base.py in __repr__(self, N_CHAR_MAX)
    258             n_max_elements_to_show=N_MAX_ELEMENTS_TO_SHOW)
    259 
--> 260         repr_ = pp.pformat(self)
    261 
    262         # Use bruteforce ellipsis when there are a lot of non-blank characters

~/anaconda3/envs/auto-ml/lib/python3.8/pprint.py in pformat(self, object)
    151     def pformat(self, object):
    152         sio = _StringIO()
--> 153         self._format(object, sio, 0, 0, {}, 0)
    154         return sio.getvalue()
    155 

~/anaconda3/envs/auto-ml/lib/python3.8/pprint.py in _format(self, object, stream, indent, allowance, context, level)
    168             self._readable = False
    169             return
--> 170         rep = self._repr(object, context, level)
    171         max_width = self._width - indent - allowance
    172         if len(rep) > max_width:

~/anaconda3/envs/auto-ml/lib/python3.8/pprint.py in _repr(self, object, context, level)
    402 
    403     def _repr(self, object, context, level):
--> 404         repr, readable, recursive = self.format(object, context.copy(),
    405                                                 self._depth, level)
    406         if not readable:

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/utils/_pprint.py in format(self, object, context, maxlevels, level)
    178 
    179     def format(self, object, context, maxlevels, level):
--> 180         return _safe_repr(object, context, maxlevels, level,
    181                           changed_only=self._changed_only)
    182 

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/utils/_pprint.py in _safe_repr(object, context, maxlevels, level, changed_only)
    423         recursive = False
    424         if changed_only:
--> 425             params = _changed_params(object)
    426         else:
    427             params = object.get_params(deep=False)

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/utils/_pprint.py in _changed_params(estimator)
     89     estimator with non-default values."""
     90 
---> 91     params = estimator.get_params(deep=False)
     92     init_func = getattr(estimator.__init__, 'deprecated_original',
     93                         estimator.__init__)

~/anaconda3/envs/auto-ml/lib/python3.8/site-packages/sklearn/base.py in get_params(self, deep)
    193         out = dict()
    194         for key in self._get_param_names():
--> 195             value = getattr(self, key)
    196             if deep and hasattr(value, 'get_params'):
    197                 deep_items = value.get_params().items()

AttributeError: 'AutoSklearnRegressor' object has no attribute 'load_models'

@eafpres
Copy link

eafpres commented Feb 14, 2021

I have the same error.

System:
WSL2 (ubuntu)
Code:

import autosklearn.classification
import sklearn.model_selection
import sklearn.datasets
import sklearn.metrics
X, y = sklearn.datasets.load_digits(return_X_y=True)
X_train, X_test, y_train, y_test = \
sklearn.model_selection.train_test_split(X, y, random_state=1)
automl = autosklearn.classification.AutoSklearnClassifier()
automl.fit(X_train, y_train)
y_hat = automl.predict(X_test)
print(“Accuracy score”, sklearn.metrics.accuracy_score(y_test, y_hat))

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/eafpres/.local/lib/python3.6/site-packages/sklearn/base.py", line 260, in __repr__
    repr_ = pp.pformat(self)
  File "/usr/lib/python3.6/pprint.py", line 144, in pformat
    self._format(object, sio, 0, 0, {}, 0)
  File "/usr/lib/python3.6/pprint.py", line 161, in _format
    rep = self._repr(object, context, level)
  File "/usr/lib/python3.6/pprint.py", line 393, in _repr
    self._depth, level)
  File "/home/eafpres/.local/lib/python3.6/site-packages/sklearn/utils/_pprint.py", line 181, in format
    changed_only=self._changed_only)
  File "/home/eafpres/.local/lib/python3.6/site-packages/sklearn/utils/_pprint.py", line 425, in _safe_repr
    params = _changed_params(object)
  File "/home/eafpres/.local/lib/python3.6/site-packages/sklearn/utils/_pprint.py", line 91, in _changed_params
    params = estimator.get_params(deep=False)
  File "/home/eafpres/.local/lib/python3.6/site-packages/sklearn/base.py", line 195, in get_params
    value = getattr(self, key)
AttributeError: 'AutoSklearnClassifier' object has no attribute 'load_models'

I decided to look at the attributes, and I see there is a _load_models:

>>> dir(automl)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_check_n_features', '_get_automl_class', '_get_param_names', '_get_tags', '_load_models', '_metric', '_more_tags', '_n_jobs', '_repr_html_', '_repr_html_inner', '_repr_mimebundle_', '_scoring_functions', '_validate_data', 'automl_', 'build_automl', 'cv_results_', 'dask_client', 'delete_output_folder_after_terminate', 'delete_tmp_folder_after_terminate', 'disable_evaluator_output', 'ensemble_nbest', 'ensemble_size', 'exclude_estimators', 'exclude_preprocessors', 'fANOVA_input_', 'fit', 'fit_ensemble', 'get_configuration_space', 'get_models_with_weights', 'get_params', 'get_smac_object_callback', 'include_estimators', 'include_preprocessors', 'initial_configurations_via_metalearning', 'logging_config', 'max_models_on_disc', 'memory_limit', 'metadata_directory', 'n_jobs', 'output_folder', 'per_run_time_limit', 'predict', 'predict_proba', 'refit', 'resampling_strategy', 'resampling_strategy_arguments', 'score', 'seed', 'set_params', 'show_models', 'smac_scenario_args', 'sprint_statistics', 'time_left_for_this_task', 'tmp_folder', 'trajectory_']

@mfeurer
Copy link
Contributor

mfeurer commented Feb 16, 2021

This was fixed via #1063 and will be present in the next release we're currently preparing via #1081.

@mfeurer mfeurer closed this as completed Feb 16, 2021
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

7 participants