Phi系数

term_id: phi_coefficient

Category: basic_concepts

Definition

Phi系数(φ)是用于衡量两个二元变量之间关联程度的指标,可视为二值变量的皮尔逊相关系数。其取值范围为-1到+1,其中0表示无关联。

Summary

衡量两个二元变量之间关联程度的统计指标。

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}')