-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostprocessing.py
More file actions
34 lines (28 loc) · 1.26 KB
/
postprocessing.py
File metadata and controls
34 lines (28 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from sklearn.metrics import classification_report, confusion_matrix
class ReportGenerator:
"""Gera relatórios avançados a partir dos resultados dos modelos.
Essa classe fornece métodos para:
- Gerar um relatório de classificação (precision, recall, F1-score)
- Visualizar a matriz de confusão de forma customizada
"""
def __init__(self, model=None):
self.model = model
def generate_classification_report(self, y_true, y_pred):
"""Gera e retorna um relatório de classificação como um DataFrame."""
report = classification_report(y_true, y_pred, output_dict=True)
return pd.DataFrame(report).transpose()
def plot_confusion_matrix(self, y_true, y_pred, normalize=False, cmap='Blues'):
"""Plota a matriz de confusão usando Seaborn."""
cm = confusion_matrix(y_true, y_pred)
if normalize:
cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
plt.figure(figsize=(8, 6))
sns.heatmap(cm, annot=True, fmt='.2f' if normalize else 'd', cmap=cmap)
plt.title('Confusion Matrix')
plt.ylabel('True label')
plt.xlabel('Predicted label')
plt.show()