-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Description of the bug
When training using Jupyter notebook and ending the code cell with model.fit(), it produces a AttributeError: 'Preprocessor' object has no attribute 'get_params'
. As per my initial testing, this does not affect the performance, therefore it is not a high priority bug—if we consider it as a bug. However, for someone new it will look like they made a mistake somewhere. I have tested this on Mambular and MLP, and for both the issue persists.
This is occurring because the Preprocessor
class of pretab
package does not have get_params. When I added the getter and setter for parameters (like in mambular/preprocessing/preprocessor.py 85f465 ) on the pretab package of my local environment, the error was resolved.
To Reproduce
Steps to reproduce the behavior:
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.preprocessing import StandardScaler
# Load California Housing dataset
data = fetch_california_housing(as_frame=True)
X, y = data.data, data.target
# Drop NAs
X = X.dropna()
y = y[X.index]
# Standard normalize features and target
y = StandardScaler().fit_transform(y.values.reshape(-1, 1)).ravel()
# Train-test-validation split
X_train, X_temp, y_train, y_temp = train_test_split(
X,
y,
test_size=0.5,
random_state=42
)
X_val, X_test, y_val, y_test = train_test_split(
X_temp,
y_temp,
test_size=0.5,
random_state=42
)
from mambular.models.mambular import MambularRegressor
model = MambularRegressor()
model.fit(X_train[:10], y_train[:10], max_epochs=1, lr=1e-04)
Expected behavior
Should not give the AttributeError: 'Preprocessor' object has no attribute 'get_params'
.
Desktop (please complete the following information):
- OS: Windows 11 with WSL and normal Windows 11 (without WSL)
- Python version: 3.12.3
- Mambular Version: v1.5.0
Additional context
Full Error Log:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\IPython\core\formatters.py:1036, in MimeBundleFormatter.__call__(self, obj, include, exclude)
1033 method = get_real_method(obj, self.print_method)
1035 if method is not None:
-> 1036 return method(include=include, exclude=exclude)
1037 return None
1038 else:
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\sklearn\utils\_repr_html\base.py:151, in ReprHTMLMixin._repr_mimebundle_(self, **kwargs)
149 output = {"text/plain": repr(self)}
150 if get_config()["display"] == "diagram":
--> 151 output["text/html"] = self._html_repr()
152 return output
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\sklearn\utils\_repr_html\estimator.py:480, in estimator_html_repr(estimator)
469 html_template = (
470 f"<style>{style_with_id}</style>"
471 f"<body>"
(...) 476 '<div class="sk-container" hidden>'
477 )
479 out.write(html_template)
--> 480 _write_estimator_html(
481 out,
482 estimator,
483 estimator.__class__.__name__,
484 estimator_str,
485 first_call=True,
486 is_fitted_css_class=is_fitted_css_class,
487 is_fitted_icon=is_fitted_icon,
488 )
489 with open(str(Path(__file__).parent / "estimator.js"), "r") as f:
490 script = f.read()
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\sklearn\utils\_repr_html\estimator.py:386, in _write_estimator_html(out, estimator, estimator_label, estimator_label_details, is_fitted_css_class, is_fitted_icon, first_call, param_prefix)
384 elif est_block.kind == "single":
385 if hasattr(estimator, "_get_params_html"):
--> 386 params = estimator._get_params_html()._repr_html_inner()
387 else:
388 params = ""
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\sklearn\base.py:274, in BaseEstimator._get_params_html(self, deep)
257 def _get_params_html(self, deep=True):
258 """
259 Get parameters for this estimator with a specific HTML representation.
260
(...) 272 form.
273 """
--> 274 out = self.get_params(deep=deep)
276 init_func = getattr(self.__init__, "deprecated_original", self.__init__)
277 init_default_params = inspect.signature(init_func).parameters
File d:\Repos\DeepTabular\mambular\models\utils\sklearn_parent.py:79, in SklearnBase.get_params(self, deep)
75 params.update(self.preprocessor_kwargs)
76 if deep:
77 preprocessor_params = {
78 key: value
---> 79 for key, value in self.preprocessor.get_params().items()
80 if key in self.preprocessor_arg_names
81 }
82 params.update(preprocessor_params)
83 return params
AttributeError: 'Preprocessor' object has no attribute 'get_params'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\IPython\core\formatters.py:406, in BaseFormatter.__call__(self, obj)
404 method = get_real_method(obj, self.print_method)
405 if method is not None:
--> 406 return method()
407 return None
408 else:
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\sklearn\utils\_repr_html\base.py:145, in ReprHTMLMixin._repr_html_inner(self)
140 def _repr_html_inner(self):
141 """This function is returned by the @property `_repr_html_` to make
142 `hasattr(estimator, "_repr_html_") return `True` or `False` depending
143 on `get_config()["display"]`.
144 """
--> 145 return self._html_repr()
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\sklearn\utils\_repr_html\estimator.py:480, in estimator_html_repr(estimator)
469 html_template = (
470 f"<style>{style_with_id}</style>"
471 f"<body>"
(...) 476 '<div class="sk-container" hidden>'
477 )
479 out.write(html_template)
--> 480 _write_estimator_html(
481 out,
482 estimator,
483 estimator.__class__.__name__,
484 estimator_str,
485 first_call=True,
486 is_fitted_css_class=is_fitted_css_class,
487 is_fitted_icon=is_fitted_icon,
488 )
489 with open(str(Path(__file__).parent / "estimator.js"), "r") as f:
490 script = f.read()
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\sklearn\utils\_repr_html\estimator.py:386, in _write_estimator_html(out, estimator, estimator_label, estimator_label_details, is_fitted_css_class, is_fitted_icon, first_call, param_prefix)
384 elif est_block.kind == "single":
385 if hasattr(estimator, "_get_params_html"):
--> 386 params = estimator._get_params_html()._repr_html_inner()
387 else:
388 params = ""
File d:\Repos\DeepTabular\deeptabular-env\Lib\site-packages\sklearn\base.py:274, in BaseEstimator._get_params_html(self, deep)
257 def _get_params_html(self, deep=True):
258 """
259 Get parameters for this estimator with a specific HTML representation.
260
(...) 272 form.
273 """
--> 274 out = self.get_params(deep=deep)
276 init_func = getattr(self.__init__, "deprecated_original", self.__init__)
277 init_default_params = inspect.signature(init_func).parameters
File d:\Repos\DeepTabular\mambular\models\utils\sklearn_parent.py:79, in SklearnBase.get_params(self, deep)
75 params.update(self.preprocessor_kwargs)
76 if deep:
77 preprocessor_params = {
78 key: value
---> 79 for key, value in self.preprocessor.get_params().items()
80 if key in self.preprocessor_arg_names
81 }
82 params.update(preprocessor_params)
83 return params
AttributeError: 'Preprocessor' object has no attribute 'get_params'