AI Terms Dictionary

A comprehensive multilingual AI terminology dictionary

Definition

The Phi coefficient (φ) is a measure of association for two binary variables, serving as the Pearson correlation coefficient for dichotomous variables. It ranges from -1 to +1, where 0 indicates no association, +1 indicates perfect positive association, and -1 indicates perfect negative association. It is widely used in contingency table analysis to determine the strength of the relationship between two categorical features, particularly in classification tasks involving binary outcomes.

Summary

A statistical measure of association between two binary variables.

Key Concepts

Use Cases

Code Example

1
2
3
4
5
6
7
8
import numpy as np
from scipy.stats import chi2_contingency
# Example: Calculate phi coefficient from a 2x2 confusion matrix
tn, fp, fn, tp = 90, 10, 5, 95
matrix = [[tn, fp], [fn, tp]]
chi2, p, dof, expected = chi2_contingency(matrix)
phi = np.sqrt(chi2 / (tn + fp + fn + tp))
print(f'Phi coefficient: {phi:.3f}')