# f_regression in sklearn - how is a correlation converted into an F score?

https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.f_regression.html#sklearn.feature_selection.f_regression

There's:

This is done in 2 steps:

1. The correlation between each regressor and the target is computed, that is, ((X[:, i] - mean(X[:, i])) * (y - mean_y)) / (std(X[:, i]) * std(y)).
2. It is converted to an F score then to a p-value.

I can't seem to find information about how one would convert a correlation between $$x_i, y$$ into an F score though.

If you know the correlation coefficient, the square of that gives coefficient of determination $$R^2$$ which gives the explained variance over total variance. From there, you can work out the F.

Using an anova table :

If we know $$R^2$$ , which is SRR / SSTO , then 1- $$R^2$$ gives us SSE / SSTO . To get an F score, we can do $$R^2$$ / (($$1 - R^2$$) / (n-2)) since the denominator will cancel out.

In the source code:

# convert to p-value
degrees_of_freedom = y.size - (2 if center else 1)
F = corr ** 2 / (1 - corr ** 2) * degrees_of_freedom
pv = stats.f.sf(F, 1, degrees_of_freedom)