Welcome to our Support Center

SparseTopKCategoricalAccuracy

Description

Computes how often integer targets are in the top K predictions. Type : polymorphic.

 

 

Input parameters

 

 y_pred : array, predicted values (one hot logits for example, [0.1, 0.8, 0.9] for 3-class problem).
 y_true : array, true values.
k : integer, number of top elements to look at for computing accuracy.

 

Output parameters

 

sparse_top_k_categorical_accuracy : float, result.

Use cases

The SparseTopKCategoricalAccuracy metric is mainly used in machine learning, specifically in multiclass classification tasks. It is useful in situations where you are interested not only in the most likely prediction (Top-1), but also in the k most likely predictions (Top-k).

Here are some examples of specific areas where SparseTopKCategoricalAccuracy can be used :

    • Image recognition : in image classification tasks, SparseTopKCategoricalAccuracy is often used to evaluate the performance of a model. For example, in a model that attempts to classify images into different categories, SparseTopKCategoricalAccuracy could be used to see if the ground truth lies in the k most likely class predictions.
    • Natural Language Processing (NLP) : SparseTopKCategoricalAccuracy is also used in NLP tasks, such as text classification, where class labels are often provided as integers. In machine translation or text generation, for example, it is often useful to look at the k best predictions.
    • Information retrieval : in the field of information retrieval, SparseTopKCategoricalAccuracy can be used to assess the quality of recommendation systems or search engines, by checking whether the item searched for is among the k best recommendations or search results.

 

Calculation

SparseTopKCategoricalAccuracy is a metric used to evaluate the performance of multiclass classification models where the labels are integers (0, 1, …, nb_classes). It compares the true labels (y_true) with the K most probable predictions of the model (y_pred), which are generally obtained via a softmax at the output of the model. If the true label is among the K most probable predictions, the prediction is considered correct. The metric is then calculated as the proportion of correct predictions out of the total set of predictions.

The parameter K is generally chosen according to the problem to be solved, and allows alternative model predictions to be taken into account.

Example

All these exemples are snippets PNG, you can drop these Snippet onto the block diagram and get the depicted code added to your VI (Do not forget to install HAIBAL library to run it).

Easy to use

Table of Contents