np.clip
for sigmoid).import numpy as np
def sigmoid_with_clipping(x):
# Clip input values to [-5, 5] range for numerical stability
x_clipped = np.clip(x, -5, 5)
# Apply sigmoid function
return 1 / (1 + np.exp(-x_clipped))
# Example usage
x = np.array([-10, -5, 0, 5, 10])
y = sigmoid_with_clipping(x)
print(f"Input: {x}")
print(f"Output: {y}")
# Output: [0.00669285 0.00669285 0.5 0.99330715 0.99330715]
Metric | Formula | Without Regularization | With Regularization | Interpretation |
---|---|---|---|---|
MSE | $\frac{1}{n} \sum_{i=1}^{n} \left( y_i - \hat{y}_i \right)^2$ | 24.5 | 26.8 | Lower is better. Slightly increases with regularization due to bias-variance tradeoff. |
RMSE | $\text{RMSE} = \sqrt{\text{MSE}}$ | 4.95 | 5.18 | Interpretable in original units. Shows actual average prediction error magnitude. |
R²-score | $1 - \frac{\text{MSE}}{\text{Var}(y)}$ | 0.98 | 0.96 | Proportion of variance explained (0-1). Should remain high with proper regularization. |
Note: Example values shown for a typical housing price prediction model. Actual values will vary by dataset and model. |