mojolearn.f_regression#
- mojolearn.f_regression(X, y, *, center=True, force_finite=True)[source]#
Compute the F-statistic of each feature’s correlation with a continuous target.
Follows scikit-learn’s
f_regression: the F-statistic and p-value of each feature’s Pearson correlation withy. Computation is float32.- Parameters:
X (array-like of shape (n_samples, n_features)) – Feature matrix.
y (array-like of shape (n_samples,)) – Target values.
center (bool, default True) – Center
Xandybefore computing the correlation.force_finite (bool, default True) – Replace non-finite results, as in scikit-learn: a constant feature or target gives F 0 and p-value 1, and a perfect correlation gives the largest float32 F and p-value 0. With False, the raw NaN and
+infvalues are returned.
- Returns:
f_statistic (array of shape (n_features,)) – F-statistic of each feature.
p_values (array of shape (n_features,)) – p-value of each F-statistic.
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 8), dtype=np.float32) >>> y = (2 * X[:, 0] + rng.random(1000)).astype(np.float32) >>> F, p = mojolearn.f_regression(X, y)