mojolearn.mutual_info_classif#
- mojolearn.mutual_info_classif(X, y, *, discrete_features='auto', n_neighbors=3, copy=True, random_state=None, n_jobs=None)[source]#
Estimate the mutual information between each feature and a discrete target.
Follows scikit-learn’s
mutual_info_classiffor denseX. Continuous features use the k-nearest neighbor estimator of Ross (2014) against the classes; discrete features use the mutual information of the contingency table. As in scikit-learn, continuous features are scaled and a small noise is added to break ties. Computation is float32.- Parameters:
X (array-like of shape (n_samples, n_features)) – Feature matrix.
y (array-like of shape (n_samples,)) – Class labels.
discrete_features (‘auto’, bool or array-like, default ‘auto’) – Which features are discrete:
'auto'(none, for denseX), a bool for all features, a boolean mask, or column indices.n_neighbors (int, default 3) – Number of neighbors for the continuous estimator, from 1 to 32 (
NotImplementedErrorotherwise).copy (bool, default True) – Accepted for scikit-learn compatibility.
random_state (int or None, default None) – Seed for the tie-breaking noise. None uses seed 0. The noise uses mojolearn’s own generator, so results differ slightly from scikit-learn’s for the same seed.
n_jobs (int, default None) – Accepted for scikit-learn compatibility.
- Returns:
mi (array of shape (n_features,)) – Estimated mutual information of each feature, in nats.
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 5), dtype=np.float32) >>> y = (X[:, 0] > 0.5).astype(np.int64) >>> mi = mojolearn.mutual_info_classif(X, y, random_state=0)