API Reference
Core Module
- class nnapprox.core.base.BaseApproximator(*, input, output, verbose=False)[source]
Bases:
ABCMinimal interface that all backends must implement.
- Concrete classes must implement:
fit– train the modelpredict– return predictions for arbitrary input formatssave/load– persistence
The
__call__method is provided here so that every subclass can be used like a plain Python function:>>> y = func(x1, x2) # scalar call >>> y_arr = func(df) # DataFrame call >>> df_out = func(df, return_dataframe=True)
- set_transform(label, *, predefined=None, forward=None, inverse=None)[source]
Register a transformation for an input or output variable.
Transformations are applied before training/prediction and inverted after prediction. This is useful for handling variables with different scales or non-linear relationships.
- Parameters:
label (str) – Name of the variable (must be in input_names or output_names)
predefined (str, optional) – Predefined transform name. Options: ‘log’, ‘log10’, ‘sqrt’, ‘square’, ‘identity’. Cannot be used with forward/inverse.
forward (Callable, optional) – Custom forward transformation function. Must be used with inverse.
inverse (Callable, optional) – Custom inverse transformation function. Must be used with forward.
- Raises:
ValueError – If label is not a known input or output name, or if both predefined and forward/inverse are provided
- Return type:
None
Examples
- Return type:
- Parameters:
Using predefined transforms:
>>> func.set_transform('x', predefined='log') >>> func.set_transform('y', predefined='sqrt')
Using custom transforms (must be defined in a module)
>>> # In my_transforms.py: >>> # def cube(x): return x**3 >>> # def cube_root(x): return x**(1/3) >>> >>> from my_transforms import cube, cube_root >>> func.set_transform('x', forward=cube, inverse=cube_root)
Notes
Custom transforms defined as lambdas or in notebooks require cloudpickle for serialization and may not be portable across Python versions.
See also
Transform.predefinedAvailable predefined transforms
PyTorch Backend
Utilities
Exceptions
Custom exceptions for nnapprox.
- exception nnapprox.core.exceptions.NNApproxError[source]
Bases:
ExceptionBase exception for nnapprox.
- exception nnapprox.core.exceptions.BackendNotAvailableError[source]
Bases:
NNApproxErrorRaised when a requested backend is not available.
- exception nnapprox.core.exceptions.ModelNotFittedError[source]
Bases:
NNApproxErrorRaised when trying to use a model that hasn’t been fitted.