package knn
import "git.sr.ht/~shulhan/pakakeh.go/lib/mining/knn"
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 ¶
const ( // TEuclidianDistance used in Runtime.DistanceMethod. TEuclidianDistance = 0 )
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) Add ¶
Add new neighbor.
func (*Neighbors) Contain ¶
Contain return true if `row` is in neighbors and their index, otherwise return false and -1.
func (*Neighbors) Distance ¶
Distance return distance value at index `idx`.
func (*Neighbors) Distances ¶
Distances return slice of distance of each neighbours.
func (*Neighbors) Len ¶
Len return the number of neighbors. This is for sort interface.
func (*Neighbors) Less ¶
Less return true if i < j. This is for sort interface.
func (*Neighbors) Replace ¶
Replace neighbor at index `idx` with new row and distance value.
func (*Neighbors) Row ¶
Row return pointer to row at index `idx`.
func (*Neighbors) Rows ¶
Rows return all rows.
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`.
func (*Neighbors) Swap ¶
Swap content of object in index i with index j. This is for sort interface.
type Runtime ¶
type Runtime struct { // AllNeighbors contain all neighbours AllNeighbors Neighbors // 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"` }
Runtime parameters for KNN processing.
func (*Runtime) ComputeEuclidianDistance ¶
ComputeEuclidianDistance compute the distance of instance with each sample in dataset `samples` and return it.
func (*Runtime) FindNeighbors ¶
func (in *Runtime) FindNeighbors(samples *tabula.Rows, instance *tabula.Row) ( kneighbors Neighbors, )
FindNeighbors Given sample set and an instance, return the nearest neighbors as a slice of neighbors.
Source Files ¶
- Version
- v0.60.0 (latest)
- Published
- Feb 1, 2025
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 9 hours ago –
Tools for package owners.