Koefisien Phi

term_id: phi_coefficient

Category: basic_concepts

Definition

Koefisien Phi (φ) adalah ukuran asosiasi untuk dua variabel biner, yang berfungsi sebagai koefisien korelasi Pearson untuk variabel dikotomi. Nilainya berkisar dari -1 hingga +1, di mana 0 menunjukkan tidak ada asosiasi.

Summary

Ukuran statistik untuk mengukur asosiasi antara dua variabel biner.

Key Concepts

  • Variabel Biner
  • Korelasi
  • Tabel Kontingensi
  • Kekuatan Asosiasi

Use Cases

  • Mengevaluasi kinerja klasifikator biner di luar akurasi
  • Menganalisis hubungan dalam data survei dengan respons ya/tidak
  • Seleksi fitur dalam dataset dengan input kategorikal

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