Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding sklearn Classification Report #496

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pytorch_tabnet/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
log_loss,
balanced_accuracy_score,
mean_squared_log_error,
classification_report
)
import torch

Expand Down Expand Up @@ -403,6 +404,36 @@ def __call__(self, y_true, y_score):
return np.sqrt(mean_squared_log_error(y_true, y_score))


class ClassificationReport(Metric):
"""
Classification Report: Precision, Recall and F1 scores.
Scikit-implementation:
https://scikit-learn.org/stable/modules/generated/sklearn.metrics.classification_report.html
"""

def __init__(self):
self._name = "classification_report"
self._maximize = False

def __call__(self, y_true, y_score):
"""
Compute precision, recall and F1 scores of predictions for each target class.

Parameters
----------
y_true : np.ndarray
Target matrix or vector
y_score : np.ndarray
Score matrix or vector

Returns
-------
str
table of precision, recall, and f1 score as well as supports
"""
return classification_report(y_true, y_score)


class UnsupervisedMetric(Metric):
"""
Unsupervised metric
Expand Down