From c55999c8d2079b683b7648ba8e9bde2b5b29af14 Mon Sep 17 00:00:00 2001 From: ppdebreuck Date: Fri, 2 May 2025 11:33:33 +0200 Subject: [PATCH 1/3] fix compatibility of older deprecated models --- modnet/models/vanilla.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/modnet/models/vanilla.py b/modnet/models/vanilla.py index 6eb8b4ff..6dea72ba 100644 --- a/modnet/models/vanilla.py +++ b/modnet/models/vanilla.py @@ -3,27 +3,25 @@ """ +import multiprocessing +import warnings from collections import defaultdict -from typing import List, Tuple, Dict, Optional, Callable, Any, Union - from pathlib import Path -import multiprocessing +from typing import Any, Callable, Dict, List, Optional, Tuple, Union -import pandas as pd import numpy as np -import warnings -from sklearn.preprocessing import StandardScaler, MinMaxScaler -from sklearn.model_selection import train_test_split -from sklearn.metrics import mean_absolute_error, mean_squared_error, roc_auc_score +import pandas as pd +import tensorflow as tf +import tqdm from sklearn.impute import SimpleImputer +from sklearn.metrics import mean_absolute_error, mean_squared_error, roc_auc_score +from sklearn.model_selection import train_test_split from sklearn.pipeline import Pipeline -import tensorflow as tf +from sklearn.preprocessing import MinMaxScaler, StandardScaler +from modnet import __version__ from modnet.preprocessing import MODData from modnet.utils import LOG -from modnet import __version__ - -import tqdm __all__ = ("MODNetModel",) @@ -532,9 +530,10 @@ def fit_preset( """ - from modnet.matbench.benchmark import matbench_kfold_splits import os + from modnet.matbench.benchmark import matbench_kfold_splits + os.environ["TF_CPP_MIN_LOG_LEVEL"] = ( "2" # many models will be fitted => reduce output ) @@ -1358,7 +1357,7 @@ def fit( history = self.model.fit(**fit_params) self.history = history.history - def predict(self, test_data: MODData, return_prob=False) -> pd.DataFrame: + def predict(self, test_data: MODData, return_prob=False, **kwargs) -> pd.DataFrame: """Predict the target values for the passed MODData. Parameters: @@ -1372,6 +1371,7 @@ class OR only return the most probable class. """ + # kwargs added for compatibility of this DeprecatedMODNetModel with ensemble (e.g. remap_out_of_bounds could be given but ignored here) # prevents Nan predictions if some features are inf x = ( test_data.get_featurized_df() From c3207257ee0f6a33c0cc4bd2e499ade8724ee526 Mon Sep 17 00:00:00 2001 From: ppdebreuck Date: Fri, 2 May 2025 13:18:09 +0200 Subject: [PATCH 2/3] clip compatibility --- modnet/models/vanilla.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modnet/models/vanilla.py b/modnet/models/vanilla.py index 6dea72ba..4a0af909 100644 --- a/modnet/models/vanilla.py +++ b/modnet/models/vanilla.py @@ -1381,6 +1381,7 @@ class OR only return the most probable class. # Scale and impute input features: if self._scale_impute is not None: + self._scale_impute.clip = False # deprecated compatibility x = self._scale_impute.transform(x) p = np.array(self.model.predict(x)) From 9249ca77e8346a5eb510fa23d697b5813bddbfd9 Mon Sep 17 00:00:00 2001 From: ppdebreuck Date: Fri, 2 May 2025 13:28:48 +0200 Subject: [PATCH 3/3] clip fix --- modnet/models/vanilla.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modnet/models/vanilla.py b/modnet/models/vanilla.py index 4a0af909..bc690298 100644 --- a/modnet/models/vanilla.py +++ b/modnet/models/vanilla.py @@ -1381,7 +1381,9 @@ class OR only return the most probable class. # Scale and impute input features: if self._scale_impute is not None: - self._scale_impute.clip = False # deprecated compatibility + self._scale_impute.named_steps["scaler"].clip = ( + False # deprecated compatibility + ) x = self._scale_impute.transform(x) p = np.array(self.model.predict(x))