metric

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package metric provides a set of metrics to calculate the accuracy of ANN predictions.

Index

Constants

View Source
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.

func (Accuracy) Calculate

func (a Accuracy) Calculate(yTrue, yHat matrix.Matrix[float64]) float64

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

func (CategoricalAccuracy) Calculate

func (c CategoricalAccuracy) Calculate(yTrue, yHat matrix.Matrix[float64]) float64

type Metric

type Metric interface {
	Calculate(yTrue, yHat matrix.Matrix[float64]) float64
}

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

func (SparseCategoricalAccuracy) Calculate

func (s SparseCategoricalAccuracy) Calculate(yTrue, yHat matrix.Matrix[float64]) float64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL