8000 MCD Exact Fit: Fixes Issue #3367 by ThatGeoGuy · Pull Request #4635 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

MCD Exact Fit: Fixes Issue #3367 #4635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions sklearn/covariance/robust_covariance.py
45F1
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _c_step(X, n_support, random_state, remaining_iterations=30,
# Iterative procedure for Minimum Covariance Determinant computation
det = fast_logdet(covariance)
previous_det = np.inf
while (det < previous_det) and (remaining_iterations > 0):
while (det < previous_det) and (remaining_iterations > 0) and not (np.isinf(det)):
# save old estimates values
previous_location = location
previous_covariance = covariance
Expand All @@ -140,16 +140,8 @@ def _c_step(X, n_support, random_state, remaining_iterations=30,

previous_dist = dist
dist = (np.dot(X - location, precision) * (X - location)).sum(axis=1)
# Catch computation errors
if np.isinf(det):
raise ValueError(
"Singular covariance matrix. "
"Please check that the covariance matrix corresponding "
"to the dataset is full rank and that MinCovDet is used with "
"Gaussian-distributed data (or at least data drawn from a "
"unimodal, symmetric distribution.")
# Check convergence
if np.allclose(det, previous_det):
if np.isinf(det) or np.allclose(det, previous_det):
# c_step procedure converged
if verbose:
print("Optimal couple (location, covariance) found before"
Expand Down Expand Up @@ -361,9 +353,10 @@ def fast_mcd(X, support_fraction=None,

X = np.asarray(X)
if X.ndim == 1:
X = np.reshape(X, (1, -1))
warnings.warn("Only one sample available. "
"You may want to reshape your data array")
X = np.reshape(X, (-1, 1))
warnings.warn("1D array passed in. "
"Assuming the array contains samples, not features. "
"You may wish to reshape your data.")
n_samples, n_features = X.shape

# minimum breakdown value
Expand Down
0