“Computing Dataset Variance Inflation Factor (VIF) Using C#” in Visual Studio Magazine

I wrote an article titled “Computing Dataset Variance Inflation Factor (VIF) Using C#” in the August 2026 edition of Microsoft Visual Studio Magazine. See https://visualstudiomagazine.com/articles/2026/08/03/computing-dataset-variance-inflation-factor-vif-using-csharp.aspx.

The variance inflation factor (VIF) of a dataset column is a value that measures the mathematical correlation of the column with other columns in the dataset. If a dataset has two or more columns that are correlated, the dataset is called multicollinear.

An extreme example of a multicollinear dataset is one in which each row represents a person, with an age column and a year-of-birth column. The two columns have near-perfect correlation — in essence, the columns contain duplicate information. In machine learning, multicollinear training data is not disastrous, but it isn’t good. Multicollinear data can make training a machine learning regression or classification model much more difficult and make model interpretability challenging or even impossible.

The article explains how to compute VIF using the C# language. The output of the article demo program is:

Begin variance inflation factor (VIF) demo using C#

Loading synthetic (20) normal data

First three lines:
  -0.1660   0.4406  -0.9998  -0.3953  -0.7065
   0.0776  -0.1616   0.3704  -0.5911   0.7562
  -0.9452   0.3409  -0.1654   0.1174  -0.7192

Begin VIF analysis
col =  0  |  vif = 1.1979
col =  1  |  vif = 1.4590
col =  2  |  vif = 1.2345
col =  3  |  vif = 1.3025
col =  4  |  vif = 1.2120

Loading synthetic (20) highly multicollinear data
(col[2] = 2.0 * col[0] + col[1] + noise)

First three lines:
  -0.1660   0.4406   0.1096  -0.3953  -0.7065
   0.0776  -0.1616  -0.0045  -0.5911   0.7562
  -0.9452   0.3409  -1.5482   0.1174  -0.7192

Begin VIF analysis
col =  0  |  vif = 25101680.1917
col =  1  |  vif = 5769710.7907
col =  2  |  vif = 30816932.6001
col =  3  |  vif = 1.2937
col =  4  |  vif = 1.1879

End demo

There are two datasets. The first dataset has normal data. The VIF values for all five columns are small, which indicates no multicollinearity. The second dataset was artificially manipulated so that columns [0], [1], [2] have a linear relation. The VIF values for those columns are extrememly large, which indicates severe multicollinearity.

If a dataset has n columns, the VIF value for a column [c] is computed by treating [c] as the dependent variable to be predicted and the other n-1 columns as the predictors, and then creating a linear regression model. If column [c] can be predicted extremely well by linear regression, it must be nearly a linear combination of the other columns.

To measure how well a linear regression model predicts, VIF uses a metric called R2, the coefficient of determination. Specifically, VIF = 1.0 / (1.0 – R2). In simplified terms, R2 can be thought of as a kind of accuracy metric. Except in weird cases, the R2 value of a linear regression model ranges from 0.0 (terrible predictions) to 1.0 (perfect predictions).

Suppose that for a column [c] that is set as the dependent variable, the R2 of the linear regression model using the other columns is 0.20 — not very good predictions. Then VIF = 1.0 / (1.0 – 0.2) = 1.0 / 0.8 = 1.25, which is a small value indicating no multicollinearity.

Now, for a different column, suppose R2 is 0.95 — the model predicts the column extremely well. VIF = 1.0 / (1.0 – 0.95) = 1.0 / 0.05 = 20.0, which is large, indicating multicollinearity. Therefore, computing VIF is essentially computing R2.

Interpreting VIF values is somewhat subjective, but typical guidelines used in data science are:

VIF is close to 1.0: The column is not correlated with other columns.
VIF is between 1.0 and 5.0: The column is mildly correlated.
VIF is between 5.0 and 10.0: The column is highly correlated.
VIF is greater than 10.0: The column is extremely correlated.

Because VIF is computed directly from R2, why not just use R2 values to identify multicollinear data? Technically, this is possible, but in practice it doesn’t work well. Because R2 is computed using squared values, R2 isn’t linear. VIF is preferred because it maps R2 values onto an unbounded scale that directly tells you how many times the variance of a coefficient estimate is inflated, making severe collinearity near R2 = 1.0 instantly obvious.



VIF analysis finds hidden patterns in data. Every cover of Playboy Magazine (except for the very first issue in December 1953) has a bunny logo. In most cases the bunny logo is clearly visible, but some covers have the logo cleverly hidden.

Left: In the June 1972 issue, the bunny logo is hidden as a knot in the model’s shirt. I’ve circled it in green for you.

Right: In the February 1973 issue, the logo is hidden in the iron work design of the chair on which the model is sitting. I’ve circled it in green.


This entry was posted in Machine Learning. Bookmark the permalink.

Leave a Reply