Skip to content

[Bug]: Export fails for Pipeline containing TransformedTargetRegressor #226

@M-Mahdi-Razmjoo

Description

@M-Mahdi-Razmjoo

Contact details

[email protected]

What happened?

Exporting a scikit-learn Pipeline that contains a TransformedTargetRegressor (TTR) step using pymilo.Export(...) fails: PyMilo raises PymiloSerializationException and reports the model has non-standard/custom internal objects.

Steps to reproduce

  1. Build a pipeline with an X-scaler and a TransformedTargetRegressor :
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import SGDRegressor
from sklearn.compose import TransformedTargetRegressor
from sklearn.pipeline import Pipeline
from pymilo import Export

reg = SGDRegressor(...)
x_scaler = StandardScaler()
y_scaler = StandardScaler()
ttr = TransformedTargetRegressor(regressor=reg, transformer=y_scaler)

pipeline = Pipeline([("x_scaler", x_scaler), ("ttr", ttr)])
Export(pipeline).save("_tmp_pipeline_ttr.json")
  1. Run the script → Export fails.

Expected behavior

PyMilo should either successfully serialize the Pipeline that contains TransformedTargetRegressor (by handling TTR).

Actual behavior

Export(pipeline) raises a PymiloSerializationException. Internally Python raises TypeError: Object of type TransformedTargetRegressor is not JSON serializable, so PyMilo cannot produce the JSON export for this composite object.

Operating system

Windows

Python version

Python 3.12

PyMilo version

PyMilo 1.3

Relevant log output

Exception type: PymiloSerializationException
Exception message: PymiloSerializationException('Pymilo Serialization failed since the given model has some non-standard customized internal objects or functions.')

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions