Go library to machine learning classification problems
Run at terminalgo get -u github.com/ai-brasil/knngo
Import the packageimport "github.com/italojs/knngo"
1º: Only the class column can be a NaN (Not a Number)
2º: The column class must be the last column.
3º: When you read your file (e.g. your .CSV file) don't worry to transform the type of your data to number, you can use the values as string.
knn.PrepareDataset(percent float32, records [][]string) (train [][]string, test [][]string, err error)
func Classify(trainData [][]string, dataToPredict []string, k int) (result string, err error)
package main
import (
"fmt"
"github.com/italojs/knngo"
)
func main (){
records := readFile("../datas/wdbc.csv")
// Use the PrepareDataset method is optional
percentToTrain := float32(0.6)
train, test, err := knn.PrepareDataset(percentToTrain, records)
if err != nil{
log.Fatalln(err)
}
// You can choose some not classificated data to classify
// The line 5 of test dataset was choosed randomicly by programmer just to example
result, err := knn.Classify(train, test[5], 10)
if err != nil{
log.Fatalln(err)
}
fmt.Println(result)
}
- *Italo Jose - Initial work - italojs
This project is licensed under the MIT License - see the LICENSE.md file for details