Documentation
¶
Overview ¶
Package metric provides a set of metrics to calculate the accuracy of ANN predictions.
Index ¶
Constants ¶
const DefaultEpsilon = 1e-5
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Accuracy ¶
type Accuracy struct {
Epsilon float64
}
Accuracy compares the prediction to the actual values.
If Epsilon is provided, the check is performed to some level of accuracy.
diff := math.Abs(pred - label)
if diff < Epsilon {
correct++
}
Different columns are treated as different samples. The correct counter goes up only if all the values per one prediction are equal to the label.
type CategoricalAccuracy ¶
type CategoricalAccuracy struct{}
CategoriacalAccuracy is a probabilistic accuracy metric, used to compare most probable guess of a neural network to the neural network output. True labels must be presented as one-hot encoded values.
Example:
ca := metrics.CategoricalAccuracy{}
yTrue, _ := matrix.NewMatrix([][]float64{{1, 0, 0}, {0, 1, 0}})
yTrue = yTrue.T()
yHat, _ := matrix.NewMatrix([][]float64{{0.78, 0.20, 0.02}, {0.10, 0.11, 0.79}})
yHat = yHat.T()
fmt.Println(ca.Calculate(yTrue, yHat)) // 0.5
type Metric ¶
Metric is an interface for calculating accuracies for the neural network output.
Calculate accepts two matrices, of size {outputSize, sampleCount} to produce a single accuracy result. If sampleCount > 1, the accuracy between different samples is averaged.
Example:
yTrue, _ := matrix.NewMatrix([][]float64{{2.3, 2.4}, {0, 1}})
yTrue = yTrue.T()
yHat, _ := matrix.NewMatrix([][]float64{{1.8, 2.5}, {0, 1}})
yHat = yHat.T()
var metric Metric
fmt.Println(metric.Calculate(yTrue, yHat)) // 0.5
type SparseCategoricalAccuracy ¶
type SparseCategoricalAccuracy struct{}
SparseCategoriacalAccuracy is a probabilistic accuracy metric, used to compare most probable guess of a neural network to the neural network output. The only difference from CategoriacalAccuracy is that true labels are presented as actual labels.
Example:
ca := metrics.SparseCategoricalAccuracy{}
yTrue, _ := matrix.NewMatrix([][]float64{{0, 1}})
yHat, _ := matrix.NewMatrix([][]float64{{0.78, 0.20, 0.02}, {0.10, 0.11, 0.79}})
yHat = yHat.T()
fmt.Println(ca.Calculate(yTrue, yHat)) // 0.5