File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 24
24
oas ,
25
25
)
26
26
27
+ from .._shrunk_covariance import _oas
28
+
27
29
X , _ = datasets .load_diabetes (return_X_y = True )
28
30
X_1d = X [:, 0 ]
29
31
n_samples , n_features = X .shape
@@ -327,6 +329,16 @@ def test_oas():
327
329
assert_almost_equal (oa .score (X ), score_ , 4 )
328
330
assert oa .precision_ is None
329
331
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
+
330
342
331
343
def test_EmpiricalCovariance_validates_mahalanobis ():
332
344
"""Checks that EmpiricalCovariance validates data with mahalanobis."""
You can’t perform that action at this time.
0 commit comments