# Exercício Prático 4 - Matriz de Confusão e Métricas de Avaliação

y_real = [1, 0, 1, 1, 0, 0, 1, 0, 0, 1]
y_pred = [1, 0, 1, 0, 0, 1, 1, 0, 0, 1]

# Inicialização dos contadores da Matriz de Confusão
vp = 0  # Verdadeiro Positivo (Real=1, Pred=1)
fp = 0  # Falso Positivo (Real=0, Pred=1)
vn = 0  # Verdadeiro Negativo (Real=0, Pred=0)
fn = 0  # Falso Negativo (Real=1, Pred=0)

# Comparação elemento a elemento
for i in range(len(y_real)):
    if y_real[i] == 1 and y_pred[i] == 1:
        vp += 1
    elif y_real[i] == 0 and y_pred[i] == 1:
        fp += 1
    elif y_real[i] == 0 and y_pred[i] == 0:
        vn += 1
    elif y_real[i] == 1 and y_pred[i] == 0:
        fn += 1

# Cálculo das métricas operacionais
total = len(y_real)
acuracia = (vp + vn) / total
precisao = vp / (vp + fp) if (vp + fp) > 0 else 0
sensibilidade = vp / (vp + fn) if (vp + fn) > 0 else 0

print("=== MATRIZ DE CONFUSÃO E AVALIAÇÃO DE DESEMPENHO ===")
print(f"Verdadeiros Positivos (VP): {vp}")
print(f"Falsos Positivos (FP): {fp}")
print(f"Verdadeiros Negativos (VN): {vn}")
print(f"Falsos Negativos (FN): {fn}")
print("-" * 45)
print(f"Acurácia Geral: {acuracia * 100:.2f}%")
print(f"Precisão: {precisao * 100:.2f}%")
print(f"Sensibilidade (Recall): {sensibilidade * 100:.2f}%")