8000 Fixes issue with singular matrices · scikit-learn/scikit-learn@2226a65 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2226a65

Browse files
committed
Fixes issue with singular matrices
1 parent b124b1c commit 2226a65

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

sklearn/covariance/robust_covariance.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _c_step(X, n_support, random_state, remaining_iterations=30,
118118
# Iterative procedure for Minimum Covariance Determinant computation
119119
det = fast_logdet(covariance)
120120
previous_det = np.inf
121-
while (det < previous_det) and (remaining_iterations > 0) and (det != -np.inf):
121+
while (det < previous_det) and (remaining_iterations > 0) and not (np.isinf(det)):
122122
# save old estimates values
123123
previous_location = location
124124
previous_covariance = covariance
@@ -140,15 +140,9 @@ def _c_step(X, n_support, random_state, remaining_iterations=30,
140140

141141
previous_dist = dist
142142
dist = (np.dot(X - location, precision) * (X - location)).sum(axis=1)
143-
# Catch computation errors
143+
# Check if best fit already found (det => 0, logdet => -inf)
144144
if np.isinf(det):
145145
results = location, covariance, det, support, dist
146-
# raise ValueError(
147-
# "Singular covariance matrix. "
148-
# "Please check that the covariance matrix corresponding "
149-
# "to the dataset is full rank and that MinCovDet is used with "
150-
# "Gaussian-distributed data (or at least data drawn from a "
151-
# "unimodal, symmetric distribution.")
152146
# Check convergence
153147
if np.allclose(det, previous_det):
154148
# c_step procedure converged

0 commit comments

Comments
 (0)
0