From 5ad2c5ef6d84763b579c22121052e875e434a119 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 17 Jan 2022 08:41:21 +0100 Subject: CART, XGBoost: Fall back to StaticFunction if no parameters are available --- lib/parameters.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/parameters.py b/lib/parameters.py index 4b6dc2c..401c7c6 100644 --- a/lib/parameters.py +++ b/lib/parameters.py @@ -924,6 +924,11 @@ class ModelAttribute: fit_parameters, category_to_index, ignore_index = param_to_ndarray( parameters, with_nan=False, categorial_to_scalar=categorial_to_scalar ) + if fit_parameters.shape[1] == 0: + logger.warning( + f"Cannot generate CART due to lack of parameters: parameter shape is {np.array(parameters).shape}, fit_parameter shape is {fit_parameters.shape}" + ) + return df.StaticFunction(np.mean(data)) cart.fit(fit_parameters, data) self.model_function = df.SKLearnRegressionFunction( np.mean(data), cart, category_to_index, ignore_index @@ -945,6 +950,11 @@ class ModelAttribute: fit_parameters, category_to_index, ignore_index = param_to_ndarray( parameters, with_nan=False, categorial_to_scalar=categorial_to_scalar ) + if fit_parameters.shape[1] == 0: + logger.warning( + f"Cannot run XGBoost due to lack of parameters: parameter shape is {np.array(parameters).shape}, fit_parameter shape is {fit_parameters.shape}" + ) + return df.StaticFunction(np.mean(data)) xgb.fit(fit_parameters, np.reshape(data, (-1, 1))) self.model_function = df.SKLearnRegressionFunction( np.mean(data), xgb, category_to_index, ignore_index -- cgit v1.2.3