8000 Adding a test for verifying the shape of imputed matrices · r2k0/scikit-learn@6f8186f · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f8186f

Browse files
Adding a test for verifying the shape of imputed matrices
1 parent 28997f6 commit 6f8186f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sklearn/preprocessing/tests/test_imputation.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ def _check_statistics(X, X_true,
7676
err_msg.format(1, True))
7777

7878

79+
def test_imputation_shape():
80+
"""Verify the shapes of the imputed matrix for different strategies."""
81+
X = np.random.randn(10, 2)
82+
X[::2] = np.nan
83+
84+
for strategy in ['mean', 'median', 'most_frequent']:
85+
imputer = Imputer(strategy=strategy)
86+
X_imputed = imputer.fit_transform(X)
87+
assert(X_imputed.shape == (10, 2))
88+
X_imputed = imputer.fit_transform(sparse.csr_matrix(X))
89+
assert(X_imputed.shape == (10, 2))
90+
91+
7992
def test_imputation_mean_median_only_zero():
8093
"""Test imputation using the mean and median strategies, when
8194
missing_values == 0."""

0 commit comments

Comments
 (0)
0