From d1f5fca655bd0c25dbc8a8bbe41e70d5cfd07ea3 Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Tue, 3 Sep 2024 16:27:30 -0400 Subject: [PATCH] Adjust for earlier scikit-learn versions Signed-off-by: Ben Wilson --- regression/steps/transform.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/regression/steps/transform.py b/regression/steps/transform.py index 981703f..8d52378 100644 --- a/regression/steps/transform.py +++ b/regression/steps/transform.py @@ -41,6 +41,12 @@ def transformer_fn(): else {"feature_names_out": "one-to-one"} ) + onehot_params = ( + {"sparse_output": False} + if Version(sklearn.__version__) >= Version("1.2") + else {"sparse": False} + ) + return Pipeline( steps=[ ( @@ -53,12 +59,12 @@ def transformer_fn(): transformers=[ ( "hour_encoder", - OneHotEncoder(categories="auto", sparse_output=False), + OneHotEncoder(categories="auto", **onehot_params), ["pickup_hour"], ), ( "day_encoder", - OneHotEncoder(categories="auto", sparse_output=False), + OneHotEncoder(categories="auto", **onehot_params), ["pickup_dow"], ), (