Metrics¶
This module provides utility functions for evaluating model performance and activation functions. It includes functions to compute the accuracy, top-k accuracy of model predictions, and the sigmoid function.
accuracy(out, yb)
¶
Computes the accuracy of model predictions.
Parameters: out (Tensor): The output tensor from the model, containing predicted class scores. yb (Tensor): The ground truth labels tensor.
Returns: Tensor: The mean accuracy of the predictions, computed as a float tensor.
Source code in openml_pytorch/metrics.py
9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
accuracy_topk(out, yb, k=5)
¶
Computes the top-k accuracy of the given model outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
out
|
Tensor
|
The output predictions of the model, of shape (batch_size, num_classes). |
required |
yb
|
Tensor
|
The ground truth labels, of shape (batch_size,). |
required |
k
|
int
|
The number of top predictions to consider. Default is 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
float |
The top-k accuracy as a float value. |
The function calculates how often the true label is among the top-k predicted labels.
Source code in openml_pytorch/metrics.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
sigmoid(x)
¶
Computes the sigmoid function
The sigmoid function is defined as 1 / (1 + exp(-x)). This function is used to map any real-valued number into the range (0, 1). It is widely used in machine learning, especially in logistic regression and neural networks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
ndarray or float
|
The input value or array over which the |
required |
Returns:
Type | Description |
---|---|
numpy.ndarray or float: The sigmoid of the input value or array. |
Source code in openml_pytorch/metrics.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|