metrics

package
v0.0.0-...-ebe581b Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAUC

func GetAUC(points [][2]float64) (float64, error)

GetAUC returns auc of the roc which is expressed by a series of points, points is sorted by FPR in monotonic increasing or monotonic order.

func GetCoordinates

func GetCoordinates(points [][3]float64) [][2]float64

GetCoordinates get the abscissa and ordinate of the point represented as [Xi,Yi,Tag], return [[Xi,Yi],...]

func GetMSE

func GetMSE(yReal []float64, yPred []float64) (float64, error)

GetMSE returns Mean Squared Error which measures the average of the squares of the errors, that is, the average squared difference between the estimated values and the actual value.

func GetRMSE

func GetRMSE(yReal []float64, yPred []float64) (float64, error)

GetRMSE returns Root Mean Squared Error which takes the square root of MSE

func GetROC

func GetROC(realClasses []string, predValues []float64, class string) ([][3]float64, error)
  • GetROC
  • Compute Receiver operating characteristic(roc).
  • PARAMS:
  • - realClasses []string: Real labels of sample set
  • - predValues []float64: Predicted Target scores, which corresponds to the sample in 'realClasses', are probability estimates of the next param 'class'.
  • - class string: The positive label in roc.
  • RERURNS:
  • - [][3]float64: a series of points on roc, the point is represented as [FPR, TPR, threshold]([x,y,threshold])
  • FPR = FP / (TN + FP), TPR = TP / (TP + FN)
  • - error: nil if succeed, error if fail

Types

type ConfusionMatrix

type ConfusionMatrix map[string]map[string]int

ConfusionMatrix is a nested map of actual and predicted class counts

func NewConfusionMatrix

func NewConfusionMatrix(realClasses []string, predClasses []string) (ConfusionMatrix, error)

NewConfusionMatrix builds a ConfusionMatrix from a set of real class value (`realClasses') and a set of predicted class value (`predClasses'). The same index of realClasses and predClasses must refer to the same sample

func (ConfusionMatrix) GetAccuracy

func (cm ConfusionMatrix) GetAccuracy() float64

GetAccuracy computes the overall classification accuracy. That is (number of correctly classified instances) / total instances

func (ConfusionMatrix) GetF1Score

func (cm ConfusionMatrix) GetF1Score(class string) (float64, error)

GetF1Score computes the harmonic mean of Precision and Recall (equivalently called F-measure).

func (ConfusionMatrix) GetFPR

func (cm ConfusionMatrix) GetFPR(class string) (float64, error)

GetFPR returns FPR which means the fraction of the misclassified samples which were not given class actually in all samples which were not given class actually.

func (ConfusionMatrix) GetFalseNegatives

func (cm ConfusionMatrix) GetFalseNegatives(class string) (float64, error)

GetFalseNegatives returns FN which means the number of times an entry is incorrectly predicted as something other than the given class.

func (ConfusionMatrix) GetFalsePositives

func (cm ConfusionMatrix) GetFalsePositives(class string) (float64, error)

GetFalsePositives returns FP which means the number of times an entry is incorrectly predicted in the ConfusionMatrix.

func (ConfusionMatrix) GetPrecision

func (cm ConfusionMatrix) GetPrecision(class string) (float64, error)

GetPrecision returns Precision which means the correctly predicted fraction of the total predictions for a given class.

func (ConfusionMatrix) GetRecall

func (cm ConfusionMatrix) GetRecall(class string) (float64, error)

GetRecall returns Recall which means the fraction of the total occurrences of a given class which were predicted.

func (ConfusionMatrix) GetTPR

func (cm ConfusionMatrix) GetTPR(class string) (float64, error)

GetTPR returns TPR which means the fraction of the total occurrences of a given class which were predicted.

func (ConfusionMatrix) GetTrueNegatives

func (cm ConfusionMatrix) GetTrueNegatives(class string) (float64, error)

GetTrueNegatives returns TN which means the number of times an entry is correctly predicted as something other than the given class.

func (ConfusionMatrix) GetTruePositives

func (cm ConfusionMatrix) GetTruePositives(class string) (float64, error)

GetTruePositives returns TP which means the number of times an entry is predicted correctly in the ConfusionMatrix.

func (ConfusionMatrix) String

func (cm ConfusionMatrix) String() string

String returns a human-readable version of the ConfusionMatrix.

func (ConfusionMatrix) Summary

func (cm ConfusionMatrix) Summary() string

Summary returns a table of precision, recall, f1, true positive, false positive, true negatives and false negatives for each class, and accuracy.

func (ConfusionMatrix) SummaryAsJSON

func (cm ConfusionMatrix) SummaryAsJSON() ([]byte, error)

SummaryAsJSON returns a json bytes of precision, recall, f1, true positive, false positive, true negatives and false negatives for each class, and accuracy. JSON type summary is something like :

{
	"Metrics": {
		"NO": {
			"TP": 2,
			"FP": 1,
			"FN": 1,
			"TN": 4,
			"Precision": 0.6666666666666666,
			"Recall": 0.6666666666666666,
			"F1Score": 0.6666666666666666
		},
		"YES": {
			"TP": 4,
			"FP": 1,
			"FN": 1,
			"TN": 2,
			"Precision": 0.8,
			"Recall": 0.8,
			"F1Score": 0.8000000000000002
		}
	},
	"Accuracy": 0.75
}

NO and Yes are classes

Jump to

Keyboard shortcuts

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