metrics

package
v0.0.0-...-708736a Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func F1

func F1(pred, correct qol.Classes) (float64, error)

F1 computes the balanced multiclass F1 score.

It is computed with the following formula:

F1 = 2 * (precision * recall) / (precision + recall)

func R1

func R1(pred1, pred0, power, margin float64) float64

R1 is the minimization inner objective function (equation 7) from "Optimizing Classifier Performance via an Approximation

to the Wilcoxon-Mann-Whitney Statistic"

by Yan, Dodier, Mozer and Wolniewicz, Proceedings of ICML 2003.

It is designed to be differentiable without too much difficulty.

pred1 = a prediction for a known target of 1 pred0 = a prediction for a known target of 0

The two meta-parameters for the optimization are margin and power: a) 0 < margin <= 1 improves generalization; and b) power > 1 controls how strongly the margin minus the difference between pred1 and pred0 is amplified; the margin-difference is raised to power before being returned.

In examples they try margin = 0.3 and power = 2; or margin = 0.2 and power = 3; but these should be optimized in an outer loop.

Yan: "In general, we can choose a value between 0.1 and 0.7 for margin. Also, we have found that power = 2 or 3 achieves similar, and generally the best results."

INVAR: power > 1.0 INVAR: 0 < margin <= 1 These invariants should be checked by the caller for speed and to allow potential inlning. They are not checked within R1().

Types

type AUCroc

type AUCroc struct {
	TargetRange TargetRange
	Auc1        float64
	Auc0        float64
	U1          float64
	U0          float64

	N1 float64
	N0 float64

	// Objective function value, set if TargetRrange.ComputeObjective is true.
	Obj float64
}

AUCroc is returned by AreaUnderROC() call.

func AreaUnderROC

func AreaUnderROC(predictor, target []float64, targetRanges []*TargetRange) (res []*AUCroc, err error)

AreaUnderROC() is for classifying a target real values as <= targetRanges[i].Threshold versus target > targetRanges[i].Threshold, for each i over the supplied targetRanges. The AUC for ROC is equivalent to the Wilcoxon or Mann-Whitney U test statistic with the relation:

AUC = U/(n0 * n1)

No NaN handling at present so handle those prior. This could be added without too much difficulty. VposSlice will sort them to the end, but another pass would be needed to keep pair-wise complete target/predictor pairs.

returns: auc1 is the area under the curve for classifying target > targetRanges[i].Threshold (typically what one wants). auc0 is the area under the curve for classifying target <= targetRanges[i].Threshold.

type ConfusionMatrix

type ConfusionMatrix struct {
	*tensor.Dense

	Labels []string    // optional Labels
	Iter   [][]float64 // a native iterator of the confusion matrix. This allows for quick access.
	// contains filtered or unexported fields
}

ConfusionMatrix represents a confusion matrix.

It is ordered in the following shape (predicted, actual)

func Confusion

func Confusion(pred, correct qol.Classes) *ConfusionMatrix

Confusion creates a Confusion Matrix.

func (*ConfusionMatrix) Heatmap

func (m *ConfusionMatrix) Heatmap() (*plot.Plot, error)

Heatmap is a convenience method to create a heatmap. It creates a *gonum.org/v1/plot.Plot, which contains a heatmap structure. The Palette, X, Y are all accessible for customization.

Not safe to be run concurrently.

type TargetRange

type TargetRange struct {
	// We just have just one threshold for now, but could be a range
	// or one range vs. another for ordinal/multiclass disrimination.
	Thresh float64

	// should we compute the U_R objective function, a differentiable
	// approximation to the Area under ROC, but designed to be minimized.
	//
	// Not implemented: actual optimization by using the derivative
	// of the objective with respect to inputs X. Hence think of
	// this simply as a proof of concept to allow comparison of
	// the actual ROC and the approximation function to check for
	// applicability on a given data context.
	//
	ComputeObjective bool
	// If ComputeObjective is true, then Margin and Power must be set.
	Margin float64 // Margin must be > 0, and Margin must <= 1.  Starting guess might be 0.2
	Power  float64 // Power must be > 1. Starting guess might be 3.0
}

TargetRange defines how to map a real target feature to a category/class.

type VposSlice

type VposSlice []vpos

VposSlice facilitates sorting.

func (VposSlice) Len

func (p VposSlice) Len() int

func (VposSlice) Less

func (p VposSlice) Less(i, j int) bool

func (VposSlice) String

func (p VposSlice) String() (r string)

func (VposSlice) Swap

func (p VposSlice) Swap(i, j int)

Jump to

Keyboard shortcuts

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