Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions modnet/models/vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,24 @@ class OR only return the most probable class.
if self._scale_impute is not None:
x = self._scale_impute.transform(x)

# Clip the scaled features to safe bounds
if self._scaler is not None:
if isinstance(self._scaler, MinMaxScaler):
# For MinMaxScaler, use 5x the feature range as bounds
lower_bound = 5.0 * self._scaler.feature_range[0]
upper_bound = 5.0 * self._scaler.feature_range[1]
elif isinstance(self._scaler, StandardScaler):
# For StandardScaler, use 10 standard deviations as bounds
lower_bound = -10.0
upper_bound = 10.0
else:
# For other scalers, use default wide bounds
lower_bound = -np.inf
upper_bound = np.inf

# Clip the features
x = np.clip(x, lower_bound, upper_bound)

p = np.array(self.model.predict(x))

if len(p.shape) == 2:
Expand Down Expand Up @@ -1445,6 +1463,24 @@ def evaluate(self, test_data: MODData) -> pd.DataFrame:
if self._scale_impute is not None:
x = self._scale_impute.transform(x)

# Clip the scaled features to safe bounds
if self._scaler is not None:
if isinstance(self._scaler, MinMaxScaler):
# For MinMaxScaler, use 5x the feature range as bounds
lower_bound = 5.0 * self._scaler.feature_range[0]
upper_bound = 5.0 * self._scaler.feature_range[1]
elif isinstance(self._scaler, StandardScaler):
# For StandardScaler, use 10 standard deviations as bounds
lower_bound = -10.0
upper_bound = 10.0
else:
# For other scalers, use default wide bounds
lower_bound = -np.inf
upper_bound = np.inf

# Clip the features
x = np.clip(x, lower_bound, upper_bound)

y_pred = np.array(self.model.predict(x))
if len(y_pred.shape) == 2:
y_pred = np.array([y_pred])
Expand Down