Source code for simpleml.transformers.base_transformer
from typing import Any, Dict, List, Optional
from sklearn.base import TransformerMixin as SklearnTransformerMixin
[docs]class TransformerMixin(SklearnTransformerMixin):
"""
Base Transformer class that implements all the necessary methods
Default behavior is to do nothing - overwrite later
"""
[docs] def reset(self) -> None:
"""
Flag to reset state to initialized values. Expects subclasses to implement
"""
raise NotImplementedError
[docs] def get_params(self, **kwargs) -> Dict[str, Any]:
"""
Should only return seeding parameters, not fit ones
(ie params of unfit object should be identical to fit object)
"""
return {}
[docs] def get_feature_names(self, input_feature_names: List[str]) -> List[str]:
return input_feature_names
[docs]class Transformer(TransformerMixin):
"""
Base Transformer class with param management - Can interfere with mro
if used as a mixin - Use `TransformerMixin` in that case
"""
def __init__(self, **kwargs):
"""
Assumes only seeding kwargs passed - will affect hash otherwise
if random unused parameters are passed
"""
self.params: Dict[str, Any] = kwargs
[docs] def get_params(self, **kwargs) -> Dict[str, Any]:
"""
Should only return seeding parameters, not fit ones
(ie params of unfit object should be identical to fit object)
"""
return self.params