Skip to content

[BUG] Fix DummyProbaRegressor._predict_var returning std dev instead of variance#976

Open
maniktyagi04 wants to merge 1 commit intosktime:mainfrom
maniktyagi04:bugfix/dummy-predict-var-std-not-variance
Open

[BUG] Fix DummyProbaRegressor._predict_var returning std dev instead of variance#976
maniktyagi04 wants to merge 1 commit intosktime:mainfrom
maniktyagi04:bugfix/dummy-predict-var-std-not-variance

Conversation

@maniktyagi04
Copy link

@maniktyagi04 maniktyagi04 commented Mar 20, 2026

Fixes #975

Summary

DummyProbaRegressor._predict_var was incorrectly returning the standard deviation (σ) of training labels instead of the variance (σ²). This PR fixes the bug and adds a dedicated test file.


Changes

skpro/regression/dummy.py

In _fit: Added storage of self._var = np.var(y.values) alongside the existing self._sigma.

# Before (buggy)
self._sigma = np.std(y.values)

# After (fixed)
self._sigma = np.std(y.values)
self._var = np.var(y.values)   # ← NEW: store variance explicitly

In _predict_var: Changed to use self._var instead of self._sigma.

# Before (buggy)
np.ones(X_n_rows) * self._sigma   # returned std dev σ

# After (fixed)
np.ones(X_n_rows) * self._var     # returns variance σ²

skpro/regression/tests/test_dummy.py (NEW)

Added 5 targeted tests for DummyProbaRegressor.predict_var:

Test What it checks
test_predict_var_equals_training_variance_empirical Returns np.var(y_train) for 'empirical' strategy
test_predict_var_equals_training_variance_normal Returns np.var(y_train) for 'normal' strategy
test_predict_var_not_equal_std Regression: does NOT return std dev
test_predict_var_is_nonnegative Variance is always ≥ 0
test_predict_var_index_and_columns Output index/columns match X_test/y_train

All 5 tests pass locally.


How to verify

python -m pytest skpro/regression/tests/test_dummy.py -v

Expected: 5 passed


Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New tests

…of variance

- In , added  alongside the existing
- In , replaced  with  so the method
  correctly returns variance (σ²) instead of standard deviation (σ)
- Added  with 5 new tests covering:
  - predict_var matches np.var(y_train) for both 'empirical' and 'normal' strategies
  - predict_var does NOT equal std dev (regression test)
  - predict_var is non-negative
  - predict_var has correct index/columns

Fixes #ISSUE_NUMBER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] DummyProbaRegressor._predict_var returns std dev (σ) instead of variance (σ²)

1 participant