evaluation

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MeanAbsoluteError = func(ctx context.Context, validationSet, forecastSet []float64, opts *forecast.EvaluationFuncOptions) (float64, int, error) {

	if len(validationSet) != len(forecastSet) {
		return 0, 0, forecast.ErrMismatchLen
	}

	var (
		n   int
		sum float64
	)

	for i := 0; i < len(validationSet); i++ {

		if err := ctx.Err(); err != nil {
			return 0.0, 0, err
		}

		actual := validationSet[i]
		predicted := forecastSet[i]

		if isInvalidFloat64(actual) || isInvalidFloat64(predicted) {
			if opts != nil && opts.SkipInvalids {
				continue
			} else {
				return 0.0, 0, forecast.ErrIndeterminate
			}
		}

		e := actual - predicted

		sum = sum + math.Abs(e)
		n = n + 1
	}

	if n == 0 {
		return 0.0, 0, forecast.ErrIndeterminate
	}

	return sum / float64(n), n, nil
}

MeanAbsoluteError represents the mean absolute error.

See: https://otexts.com/fpp2/accuracy.html

View Source
var MeanAbsolutePercentageError = func(ctx context.Context, validationSet, forecastSet []float64, opts *forecast.EvaluationFuncOptions) (float64, int, error) {

	if len(validationSet) != len(forecastSet) {
		return 0, 0, forecast.ErrMismatchLen
	}

	var (
		n   int
		sum float64
	)

	for i := 0; i < len(validationSet); i++ {

		if err := ctx.Err(); err != nil {
			return 0.0, 0, err
		}

		actual := validationSet[i]
		predicted := forecastSet[i]

		if isInvalidFloat64(actual) || isInvalidFloat64(predicted) || actual == 0 {
			if opts != nil && opts.SkipInvalids {
				continue
			} else {
				return 0.0, 0, forecast.ErrIndeterminate
			}
		}

		e := actual - predicted

		sum = sum + math.Abs(100*e/actual)
		n = n + 1
	}

	if n == 0 {
		return 0.0, 0, forecast.ErrIndeterminate
	}

	return sum / float64(n), n, nil
}

MeanAbsolutePercentageError represents the mean absolute percentage error.

See: https://otexts.com/fpp2/accuracy.html

View Source
var RootMeanSquaredError = func(ctx context.Context, validationSet, forecastSet []float64, opts *forecast.EvaluationFuncOptions) (float64, int, error) {

	if len(validationSet) != len(forecastSet) {
		return 0, 0, forecast.ErrMismatchLen
	}

	if len(validationSet) == 0 {
		return 0.0, 0, forecast.ErrIndeterminate
	}

	sse, n, err := SumOfSquaredErrors(ctx, validationSet, forecastSet, opts)
	if err != nil {
		return 0.0, 0, err
	}

	return math.Sqrt(sse / float64(n)), n, nil
}

RootMeanSquaredError represents the root mean squared error.

See: https://otexts.com/fpp2/accuracy.html

View Source
var SumOfSquaredErrors = func(ctx context.Context, validationSet, forecastSet []float64, opts *forecast.EvaluationFuncOptions) (float64, int, error) {

	if len(validationSet) != len(forecastSet) {
		return 0, 0, forecast.ErrMismatchLen
	}

	var (
		n   int
		sum float64
	)

	for i := 0; i < len(validationSet); i++ {

		if err := ctx.Err(); err != nil {
			return 0.0, 0, err
		}

		actual := validationSet[i]
		predicted := forecastSet[i]

		if isInvalidFloat64(actual) || isInvalidFloat64(predicted) {
			if opts != nil && opts.SkipInvalids {
				continue
			} else {
				return 0.0, 0, forecast.ErrIndeterminate
			}
		}

		e := actual - predicted

		sum = sum + e*e
		n = n + 1
	}

	return sum, n, nil
}

SumOfSquaredErrors calculates the sum of squared errors.

NOTE: This is not for validation.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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