pytagi.metric#

Classes#

HRCSoftmaxMetric

Classification error metric for Hierarchical Softmax.

Functions#

mse(→ float)

Calculates the Mean Squared Error (MSE).

log_likelihood(→ float)

Computes the log-likelihood.

rmse(→ float)

Calculates the Root Mean Squared Error (RMSE).

classification_error(→ float)

Computes the classification error rate.

Module Contents#

class pytagi.metric.HRCSoftmaxMetric(num_classes: int)[source]#

Classification error metric for Hierarchical Softmax.

This class provides methods to compute the error rate and get predicted labels for a classification model that uses Hierarchical Softmax.

Initializes the HRCSoftmaxMetric.

Parameters:

num_classes (int) – The total number of classes in the classification problem.

error_rate(m_pred: numpy.ndarray, v_pred: numpy.ndarray, label: numpy.ndarray) float[source]#

Computes the classification error rate.

This method calculates the proportion of incorrect predictions by comparing the predicted labels against the true labels.

Parameters:
  • m_pred (np.ndarray) – The mean of the predictions from the model.

  • v_pred (np.ndarray) – The variance of the predictions from the model.

  • label (np.ndarray) – The ground truth labels.

Returns:

The classification error rate, a value between 0 and 1.

Return type:

float

get_predicted_labels(m_pred: numpy.ndarray, v_pred: numpy.ndarray) numpy.ndarray[source]#

Gets the predicted class labels from the model’s output.

Parameters:
  • m_pred (np.ndarray) – The mean of the predictions from the model.

  • v_pred (np.ndarray) – The variance of the predictions from the model.

Returns:

An array of predicted class labels.

Return type:

np.ndarray

pytagi.metric.mse(prediction: numpy.ndarray, observation: numpy.ndarray) float[source]#

Calculates the Mean Squared Error (MSE).

MSE measures the average of the squares of the errors, i.e., the average squared difference between the estimated and the observed values.

Parameters:
  • prediction (np.ndarray) – The predicted values.

  • observation (np.ndarray) – The actual (observed) values.

Returns:

The mean squared error.

Return type:

float

pytagi.metric.log_likelihood(prediction: numpy.ndarray, observation: numpy.ndarray, std: numpy.ndarray) float[source]#

Computes the log-likelihood.

This function assumes the likelihood of the observation given the prediction is a Gaussian distribution with a given standard deviation.

Parameters:
  • prediction (np.ndarray) – The predicted mean of the distribution.

  • observation (np.ndarray) – The observed data points.

  • std (np.ndarray) – The standard deviation of the distribution.

Returns:

The average log-likelihood value.

Return type:

float

pytagi.metric.rmse(prediction: numpy.ndarray, observation: numpy.ndarray) float[source]#

Calculates the Root Mean Squared Error (RMSE).

RMSE is the square root of the mean of the squared errors.

Parameters:
  • prediction (np.ndarray) – The predicted values.

  • observation (np.ndarray) – The actual (observed) values.

Returns:

The root mean squared error.

Return type:

float

pytagi.metric.classification_error(prediction: numpy.ndarray, label: numpy.ndarray) float[source]#

Computes the classification error rate.

This function calculates the fraction of predictions that do not match the true labels.

Parameters:
  • prediction (np.ndarray) – An array of predicted labels.

  • label (np.ndarray) – An array of true labels.

Returns:

The classification error rate (proportion of incorrect predictions).

Return type:

float