mojolearn.mutual_info_regression#

mojolearn.mutual_info_regression(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 continuous target.

Follows scikit-learn’s mutual_info_regression for dense X. Continuous features use the k-nearest neighbor estimator of Kraskov et al. (2004); discrete features use Ross’s (2014) estimator with the feature’s categories as the classes. As in scikit-learn, continuous variables 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,)) – Target values.

  • discrete_features (‘auto’, bool or array-like, default ‘auto’) – Which features are discrete: 'auto' (none, for dense X), a bool for all features, a boolean mask, or column indices.

  • n_neighbors (int, default 3) – Number of neighbors, from 1 to 32 (NotImplementedError otherwise).

  • 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] ** 2 + 0.1 * rng.random(1000)).astype(np.float32)
>>> mi = mojolearn.mutual_info_regression(X, y, random_state=0)