Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Univariate fast_mcd: np.reshape(X, (-1, 1)) #4517

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 5 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
18 changes: 7 additions & 11 deletions sklearn/covariance/robust_covariance.py
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,14 +140,9 @@ 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
# Check if best fit already found (det => 0, logdet => -inf)
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.")
results = location, covariance, det, support, dist
# Check convergence
if np.allclose(det, previous_det):
# c_step procedure converged
Expand Down Expand Up @@ -361,9 +356,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