Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-255

VIF for Two Variables

Problem

Compute the variance inflation factor for two variables: 1 / (1 - r^2) where r is their Pearson correlation.

Return 0.0 if a variance is 0 or |r| = 1.

Hint

VIF explodes as the two predictors become collinear.

Test cases

case 1
in: [[1,2,3],[2,4,6]]
expected: 0
case 2
in: [[1,2,3,4],[1,3,2,5]]
expected: 3.240740740740738
case 3
in: [[1,1,1],[1,2,3]]
expected: 0
case 4
in: [[],[]]
expected: 0
Starter codePython
def vif_two_variables(x1, x2):
    # Your code here
    pass

4 test cases · run your code against them in the editor