alpbench.util.pytorch_tabnet.metrics¶

Functions

UnsupervisedLoss(y_pred, embedded_x, obf_vars)

Implements unsupervised loss function.

UnsupervisedLossNumpy(y_pred, embedded_x, ...)

check_metrics(metrics)

Check if custom metrics are provided.

Classes

AUC()

AUC.

Accuracy()

Accuracy.

BalancedAccuracy()

Balanced Accuracy.

LogLoss()

LogLoss.

MAE()

Mean Absolute Error.

MSE()

Mean Squared Error.

Metric()

MetricContainer(metric_names[, prefix])

Container holding a list of metrics.

RMSE()

Root Mean Squared Error.

RMSLE()

Root Mean squared logarithmic error regression loss.

UnsupMetricContainer(metric_names[, prefix])

Container holding a list of metrics.

UnsupervisedMetric()

Unsupervised metric

UnsupervisedNumpyMetric()

Unsupervised metric

class alpbench.util.pytorch_tabnet.metrics.AUC[source]¶

Bases: Metric

AUC.

__call__(y_true, y_score)[source]¶

Compute AUC of predictions.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_score (np.ndarray) – Score matrix or vector

Returns:

AUC of predictions vs targets.

Return type:

float

class alpbench.util.pytorch_tabnet.metrics.Accuracy[source]¶

Bases: Metric

Accuracy.

__call__(y_true, y_score)[source]¶

Compute Accuracy of predictions.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_score (np.ndarray) – Score matrix or vector

Returns:

Accuracy of predictions vs targets.

Return type:

float

class alpbench.util.pytorch_tabnet.metrics.BalancedAccuracy[source]¶

Bases: Metric

Balanced Accuracy.

__call__(y_true, y_score)[source]¶

Compute Accuracy of predictions.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_score (np.ndarray) – Score matrix or vector

Returns:

Accuracy of predictions vs targets.

Return type:

float

class alpbench.util.pytorch_tabnet.metrics.LogLoss[source]¶

Bases: Metric

LogLoss.

__call__(y_true, y_score)[source]¶

Compute LogLoss of predictions.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_score (np.ndarray) – Score matrix or vector

Returns:

LogLoss of predictions vs targets.

Return type:

float

class alpbench.util.pytorch_tabnet.metrics.MAE[source]¶

Bases: Metric

Mean Absolute Error.

__call__(y_true, y_score)[source]¶

Compute MAE (Mean Absolute Error) of predictions.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_score (np.ndarray) – Score matrix or vector

Returns:

MAE of predictions vs targets.

Return type:

float

class alpbench.util.pytorch_tabnet.metrics.MSE[source]¶

Bases: Metric

Mean Squared Error.

__call__(y_true, y_score)[source]¶

Compute MSE (Mean Squared Error) of predictions.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_score (np.ndarray) – Score matrix or vector

Returns:

MSE of predictions vs targets.

Return type:

float

class alpbench.util.pytorch_tabnet.metrics.Metric[source]¶

Bases: object

__call__(y_true, y_pred)[source]¶
classmethod get_metrics_by_names(names)[source]¶

Get list of metric classes.

Parameters:
  • cls (Metric) – Metric class.

  • names (list) – List of metric names.

Returns:

metrics – List of metric classes.

Return type:

list

class alpbench.util.pytorch_tabnet.metrics.MetricContainer(metric_names, prefix='')[source]¶

Bases: object

Container holding a list of metrics.

Parameters:
  • metric_names (list of str) – List of metric names.

  • prefix (str) – Prefix of metric names.

__call__(y_true, y_pred)[source]¶

Compute all metrics and store into a dict.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_pred (np.ndarray) – Score matrix or vector

Returns:

Dict of metrics ({metric_name: metric_value}).

Return type:

dict

metric_names: list[str]¶
prefix: str = ''¶
class alpbench.util.pytorch_tabnet.metrics.RMSE[source]¶

Bases: Metric

Root Mean Squared Error.

__call__(y_true, y_score)[source]¶

Compute RMSE (Root Mean Squared Error) of predictions.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_score (np.ndarray) – Score matrix or vector

Returns:

RMSE of predictions vs targets.

Return type:

float

class alpbench.util.pytorch_tabnet.metrics.RMSLE[source]¶

Bases: Metric

Root Mean squared logarithmic error regression loss. Scikit-implementation: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_log_error.html Note: In order to avoid error, negative predictions are clipped to 0. This means that you should clip negative predictions manually after calling predict.

__call__(y_true, y_score)[source]¶

Compute RMSLE of predictions.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_score (np.ndarray) – Score matrix or vector

Returns:

RMSLE of predictions vs targets.

Return type:

float

class alpbench.util.pytorch_tabnet.metrics.UnsupMetricContainer(metric_names, prefix='')[source]¶

Bases: object

Container holding a list of metrics.

Parameters:
  • y_pred (torch.Tensor or np.array) – Reconstructed prediction (with embeddings)

  • embedded_x (torch.Tensor) – Original input embedded by network

  • obf_vars (torch.Tensor) – Binary mask for obfuscated variables. 1 means the variables was obfuscated so reconstruction is based on this.

__call__(y_pred, embedded_x, obf_vars)[source]¶

Compute all metrics and store into a dict.

Parameters:
  • y_true (np.ndarray) – Target matrix or vector

  • y_pred (np.ndarray) – Score matrix or vector

Returns:

Dict of metrics ({metric_name: metric_value}).

Return type:

dict

metric_names: list[str]¶
prefix: str = ''¶
class alpbench.util.pytorch_tabnet.metrics.UnsupervisedMetric[source]¶

Bases: Metric

Unsupervised metric

__call__(y_pred, embedded_x, obf_vars)[source]¶

Compute MSE (Mean Squared Error) of predictions.

Parameters:
  • y_pred (torch.Tensor or np.array) – Reconstructed prediction (with embeddings)

  • embedded_x (torch.Tensor) – Original input embedded by network

  • obf_vars (torch.Tensor) – Binary mask for obfuscated variables. 1 means the variables was obfuscated so reconstruction is based on this.

Returns:

MSE of predictions vs targets.

Return type:

float

class alpbench.util.pytorch_tabnet.metrics.UnsupervisedNumpyMetric[source]¶

Bases: Metric

Unsupervised metric

__call__(y_pred, embedded_x, obf_vars)[source]¶

Compute MSE (Mean Squared Error) of predictions.

Parameters:
  • y_pred (torch.Tensor or np.array) – Reconstructed prediction (with embeddings)

  • embedded_x (torch.Tensor) – Original input embedded by network

  • obf_vars (torch.Tensor) – Binary mask for obfuscated variables. 1 means the variables was obfuscated so reconstruction is based on this.

Returns:

MSE of predictions vs targets.

Return type:

float

alpbench.util.pytorch_tabnet.metrics.UnsupervisedLoss(y_pred, embedded_x, obf_vars, eps=1e-09)[source]¶

Implements unsupervised loss function. This differs from orginal paper as it’s scaled to be batch size independent and number of features reconstructed independent (by taking the mean)

Parameters:
  • y_pred (torch.Tensor or np.array) – Reconstructed prediction (with embeddings)

  • embedded_x (torch.Tensor) – Original input embedded by network

  • obf_vars (torch.Tensor) – Binary mask for obfuscated variables. 1 means the variable was obfuscated so reconstruction is based on this.

  • eps (float) – A small floating point to avoid ZeroDivisionError This can happen in degenerated case when a feature has only one value

Returns:

loss – Unsupervised loss, average value over batch samples.

Return type:

torch float

alpbench.util.pytorch_tabnet.metrics.UnsupervisedLossNumpy(y_pred, embedded_x, obf_vars, eps=1e-09)[source]¶
alpbench.util.pytorch_tabnet.metrics.check_metrics(metrics)[source]¶

Check if custom metrics are provided.

Parameters:

metrics (list of str or classes) – List with built-in metrics (str) or custom metrics (classes).

Returns:

val_metrics – List of metric names.

Return type:

list of str