Documentation ¶
Overview ¶
Package knn implement the K Nearest Neighbor using Euclidean to compute the distance between samples.
Index ¶
- Constants
- type Neighbors
- func (neighbors *Neighbors) Add(row *tabula.Row, distance float64)
- func (neighbors *Neighbors) Contain(row *tabula.Row) (bool, int)
- func (neighbors *Neighbors) Distance(idx int) float64
- func (neighbors *Neighbors) Distances() *[]float64
- func (neighbors *Neighbors) Len() int
- func (neighbors *Neighbors) Less(i, j int) bool
- func (neighbors *Neighbors) Replace(idx int, row *tabula.Row, distance float64)
- func (neighbors *Neighbors) Row(idx int) *tabula.Row
- func (neighbors *Neighbors) Rows() *[]*tabula.Row
- func (neighbors *Neighbors) SelectRange(start, end int) (newn Neighbors)
- func (neighbors *Neighbors) SelectWhere(idx int, val string) (newn Neighbors)
- func (neighbors *Neighbors) Swap(i, j int)
- type Runtime
Constants ¶
View Source
const (
// TEuclidianDistance used in Runtime.DistanceMethod.
TEuclidianDistance = 0
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Neighbors ¶
type Neighbors struct {
// contains filtered or unexported fields
}
Neighbors is a mapping between sample and their distance. This type implement the sort interface.
func (*Neighbors) Contain ¶
Contain return true if `row` is in neighbors and their index, otherwise return false and -1.
func (*Neighbors) SelectRange ¶
SelectRange select all neighbors from index `start` to `end`. Return an empty set if start or end is out of range.
func (*Neighbors) SelectWhere ¶
SelectWhere return all neighbors where row value at index `idx` is equal to string `val`.
type Runtime ¶
type Runtime struct { // DistanceMethod define how the distance between sample will be // measured. DistanceMethod int // ClassIndex define index of class in dataset. ClassIndex int `json:"ClassIndex"` // K define number of nearest neighbors that will be searched. K int `json:"K"` // AllNeighbors contain all neighbours AllNeighbors Neighbors }
Runtime parameters for KNN processing.
func (*Runtime) ComputeEuclidianDistance ¶
ComputeEuclidianDistance compute the distance of instance with each sample in dataset `samples` and return it.
Click to show internal directories.
Click to hide internal directories.