8000 add test to improve coverage · scikit-learn/scikit-learn@e3abc1e · GitHub
[go: up one dir, main page]

Skip to content

Commit e3abc1e

Browse files
committed
add test to improve coverage
1 parent 6a7d1c1 commit e3abc1e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sklearn/covariance/tests/test_covariance.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
oas,
2525
)
2626

27+
from .._shrunk_covariance import _oas
28+
2729
X, _ = datasets.load_diabetes(return_X_y=True)
2830
X_1d = X[:, 0]
2931
n_samples, n_features = X.shape
@@ -327,6 +329,16 @@ def test_oas():
327329
assert_almost_equal(oa.score(X), score_, 4)
328330
assert oa.precision_ is None
329331

332+
# test function _oas without assuming centered data
333+
X_1d = X[:, 0:1]
334+
oa = OAS()
335+
oa.fit(X_1d)
336+
# compare shrunk covariance obtained from data and from MLE estimate
337+
_oa_cov_from_mle, _oa_shrinkage_from_mle = _oas(X_1d)
338+
assert_array_almost_equal(_oa_cov_from_mle, oa.covariance_, 4)
339+
assert_almost_equal(_oa_shrinkage_from_mle, oa.shrinkage_)
340+
assert_array_almost_equal((X_1d**2).sum() / n_samples, oa.covariance_, 4)
341+
330342

331343
def test_EmpiricalCovariance_validates_mahalanobis():
332344
"""Checks that EmpiricalCovariance validates data with mahalanobis."""

0 commit comments

Comments
 (0)
0