フィ係数

term_id: phi_coefficient

Category: basic_concepts

Definition

フィ係数(φ)は、2つの二値変数の間の関連性を測る指標であり、二分変数に対するピアソン相関係数として機能します。-1から+1の範囲を取り、0は無相関を意味します。

Summary

2つの二値変数の間の関連性を測る統計指標。

Key Concepts

  • 二値変数
  • 相関
  • 分割表
  • 関連の強さ

Use Cases

  • 精度以外のバイナリ分類器のパフォーマンス評価
  • Yes/No回答を含む調査データの関係性分析
  • カテゴリカル入力を持つデータセットにおける特徴量選択

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