Phi-koefficient

term_id: phi_coefficient

Category: basic_concepts

Definition

Phi-koefficienten (φ) er et mål for sammenhæng mellem to binære variable og fungerer som Pearsons korrelationskoefficient for dikotome variable. Den varierer fra -1 til +1, hvor 0 indikerer ingen sammenhæng.

Summary

Et statistisk mål for sammenhængen mellem to binære variable.

Key Concepts

  • Binære variable
  • Korrelation
  • Kontingenstabel
  • Sammenhængsstyrke

Use Cases

  • Vurdering af ydeevnen hos en binær klassifikator ud over nøjagtighed
  • Analyse af sammenhænge i spørgeskema-data med ja/nej-svar
  • Funktionsselvvalg i datasæt med kategoriske input

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