Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bsm/mlmetrics

Common metrics for evaluation of machine learning models
https://github.com/bsm/mlmetrics

classification confusion-matrix golang kappa logloss machine-learning matthews ml online-machine-learning r2 regression

Last synced: 11 days ago
JSON representation

Common metrics for evaluation of machine learning models

Awesome Lists containing this project

README

        

# ML metrics

[![GoDoc](https://godoc.org/github.com/bsm/mlmetrics?status.svg)](https://godoc.org/github.com/bsm/mlmetrics)
[![Test](https://github.com/bsm/openmetrics/actions/workflows/test.yml/badge.svg)](https://github.com/bsm/openmetrics/actions/workflows/test.yml)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

Common metrics for evaluation of machine learning models.

Goals:

* Fast!
* Thread-safe
* Support for online evaluation

## Supported Metrics

Classification:

* [Accuracy](https://en.wikipedia.org/wiki/Accuracy_and_precision)
* [Confusion Matrix](https://en.wikipedia.org/wiki/Confusion_matrix)
* [F1 Score](https://en.wikipedia.org/wiki/F1_score)
* [Kappa](https://en.wikipedia.org/wiki/Cohen%27s_kappa)
* [Matthews](https://en.wikipedia.org/wiki/Matthews_correlation_coefficient)
* [LogLoss](https://en.wikipedia.org/wiki/Loss_functions_for_classification)
* [Precision](https://en.wikipedia.org/wiki/Information_retrieval#Precision)
* [Sensitivity](https://en.wikipedia.org/wiki/Sensitivity_(test))

Regression:

* [Mean Absolute Error](https://en.wikipedia.org/wiki/Mean_absolute_error)
* [Mean Squared Error](https://en.wikipedia.org/wiki/Mean_squared_error)
* [Root Mean Squared Error](https://en.wikipedia.org/wiki/Root-mean-square_deviation)
* [Mean Squared Error](https://en.wikipedia.org/wiki/Root-mean-square_deviation)
* [R²](https://en.wikipedia.org/wiki/Coefficient_of_determination)

## Documentation

Documentation and example are available via godoc at http://godoc.org/github.com/bsm/mlmetrics

## Example

```go
package main

import (
"github.com/bsm/mlmetrics"
)

func main() {
yTrue := []int{2, 0, 2, 2, 0, 1}
yPred := []int{0, 0, 2, 2, 0, 2}

mat := mlmetrics.NewConfusionMatrix()
for i := range yTrue {
mat.Observe(yTrue[i], yPred[i])
}

// print matrix
for i := 0; i < mat.Order(); i++ {
fmt.Println(mat.Row(i))
}

// print metrics
fmt.Println()
fmt.Printf("accuracy : %.3f\n", mat.Accuracy())
fmt.Printf("kappa : %.3f\n", mat.Kappa())
fmt.Printf("matthews : %.3f\n", mat.Matthews())

}
```