| 1 | diff --git a/sklearn/feature_selection/mutual_info_.py b/sklearn/feature_selection/mutual_info_.py |
| 2 | --- a/sklearn/feature_selection/mutual_info_.py |
| 3 | +++ b/sklearn/feature_selection/mutual_info_.py |
| 4 | @@ -10,7 +10,7 @@ |
| 5 | from ..preprocessing import scale |
| 6 | from ..utils import check_random_state |
| 7 | from ..utils.fixes import _astype_copy_false |
| 8 | -from ..utils.validation import check_X_y |
| 9 | +from ..utils.validation import check_array, check_X_y |
| 10 | from ..utils.multiclass import check_classification_targets |
| 11 | |
| 12 | |
| 13 | @@ -247,14 +247,16 @@ def _estimate_mi(X, y, discrete_features='auto', discrete_target=False, |
| 14 | X, y = check_X_y(X, y, accept_sparse='csc', y_numeric=not discrete_target) |
| 15 | n_samples, n_features = X.shape |
| 16 | |
| 17 | - if discrete_features == 'auto': |
| 18 | - discrete_features = issparse(X) |
| 19 | - |
| 20 | - if isinstance(discrete_features, bool): |
| 21 | + if isinstance(discrete_features, (str, bool)): |
| 22 | + if isinstance(discrete_features, str): |
| 23 | + if discrete_features == 'auto': |
| 24 | + discrete_features = issparse(X) |
| 25 | + else: |
| 26 | + raise ValueError("Invalid string value for discrete_features.") |
| 27 | discrete_mask = np.empty(n_features, dtype=bool) |
| 28 | discrete_mask.fill(discrete_features) |
| 29 | else: |
| 30 | - discrete_features = np.asarray(discrete_features) |
| 31 | + discrete_features = check_array(discrete_features, ensure_2d=False) |
| 32 | if discrete_features.dtype != 'bool': |
| 33 | discrete_mask = np.zeros(n_features, dtype=bool) |
| 34 | discrete_mask[discrete_features] = True |