Troubleshooting¶
Common errors when working with Sklearn-Wrap, their causes, and how to fix them.
Wrapper Definition Errors¶
Missing _estimator_name¶
Cause: The wrapper class does not define _estimator_name as a string class attribute.
Fix: Add a string attribute to your wrapper class:
class MyWrapper(BaseClassWrapper, RegressorMixin):
_estimator_name = "regressor"
_estimator_base_class = object
Missing _estimator_base_class¶
Cause: The wrapper class does not define _estimator_base_class.
Fix: Add a class attribute. Use object to accept any class, or a specific base class for stricter validation:
Constructor Errors¶
Missing Required Parameter¶
Cause: The wrapped class was not passed when creating the wrapper, and no _estimator_default_class is defined.
Fix: Pass the class to wrap using the keyword matching _estimator_name:
If the wrapper should have a sensible default, define _estimator_default_class:
class MyWrapper(BaseClassWrapper, RegressorMixin):
_estimator_name = "regressor"
_estimator_base_class = object
_estimator_default_class = MyDefaultEstimator
Estimator Is Not a Class¶
Cause: An instance was passed instead of a class. The wrapper expects a class (not an instantiated object) because it handles instantiation itself during fit().
Fix: Pass the class, not an instance:
# Wrong
wrapper = MyWrapper(regressor=MyEstimator())
# Correct
wrapper = MyWrapper(regressor=MyEstimator)
Wrong Base Class¶
ValueError: Invalid regressor class WrongClass for estimator MyWrapper.
Valid estimator class should be derived from ExpectedBase.
Cause: The passed class does not inherit from _estimator_base_class.
Fix: Either pass a class that inherits from the expected base, or widen the constraint:
Parameter Errors¶
Reserved Delimiter in Parameter Name¶
ValueError: Parameter name my__param cannot contain '__' (double underscore).
This delimiter is reserved for nested parameter syntax.
Cause: The wrapped class has a constructor parameter containing __, which conflicts with Scikit-Learn's nested parameter syntax.
Fix: Rename the parameter in the wrapped class, or create an adapter class that translates the parameter name:
Invalid Parameter Name¶
Cause: A keyword argument was passed to the wrapper that does not match any constructor parameter of the wrapped class.
Fix: Check the wrapped class's __init__ signature for valid parameter names.
Cannot Change Estimator Class¶
ValueError: Cannot change estimator class via set_params.
The 'regressor' parameter cannot be set. Redeclare the estimator...
Cause: set_params() was called trying to change the wrapped class itself.
Fix: Create a new wrapper instance with the different class:
# Wrong
wrapper.set_params(regressor=DifferentClass)
# Correct
new_wrapper = MyWrapper(regressor=DifferentClass, alpha=1.0)
Fit-Time Errors¶
Required Parameter Still Unset¶
Cause: The wrapped class has a required constructor parameter (no default value) that was not provided when creating the wrapper.
Fix: Pass all required parameters:
Unfitted Estimator¶
Cause: predict() or transform() was called before fit().
Fix: Call fit() first:
Nested Parameter Errors¶
Invalid Nested Parameter¶
ValueError: Invalid parameter inner_alpha for estimator MyWrapper.
Valid parameters are: ['regressor', 'alpha', 'beta']
Cause: The base key of a nested parameter (before the first __) does not match any wrapper parameter.
Fix: Check wrapper.get_params() for valid parameter names. Nested parameters use __ to separate levels:
Nested Object Missing set_params¶
AttributeError: Cannot set nested parameters on inner.
Object of type int does not have a set_params method.
Cause: Double-underscore syntax was used to reach into a parameter that is not itself an estimator or wrapper.
Fix: Only use __ syntax for parameters that are BaseClassWrapper instances or Scikit-Learn estimators with set_params().
YAML Configuration Errors¶
Untrusted Module¶
Cause: The YAML config references a class from a module not in the trusted allowlist.
Fix: Add the module to trusted modules:
from sklearn_wrap.config import set_config
set_config(trusted_modules=frozenset({"sklearn", "sklearn_wrap", "xgboost"}))
See Also¶
- How to Validate Parameters: adding parameter constraints
- How to Test Your Wrapper: verifying wrapper correctness
- Configuration Reference: all wrapper class attributes