I'm playing around with the knnclassifier_iris.go example in the golearn examples folder. I replaced the iris dataset with one of my own, and as long as I train my data on some percentage of the data I read in, all functions work fine and I get some output. However, when I clearly mention a training and testing dataset, and then run predict on the test dataset after fitting the training dataset, I get a nil result when I try to print the predictions. I don't know why I'm getting a nil value, so I would really appreciate some help.
My code:
package main
import (
"fmt"
"github.com/sjwhitworth/golearn/base"
"github.com/sjwhitworth/golearn/evaluation"
"github.com/sjwhitworth/golearn/knn"
)
func main() {
trainData, err := base.ParseCSVToInstances("~/Desktop/churn_train.csv", true)
if err != nil {
panic(err)
}
fmt.Println(trainData)
testData, err := base.ParseCSVToInstances("~/Desktop/churn_test.csv", false)
if err != nil {
panic(err)
}
fmt.Println(trainData)
fmt.Println(testData)
//Initialises a new KNN classifier
cls := knn.NewKnnClassifier("euclidean", 2)
cls.Fit(trainData)
//Calculates the Euclidean distance and returns the most popular label
predictions := cls.Predict(testData)
fmt.Println(predictions) //GETTING <NIL> AS OUTPUT
// Prints precision/recall metrics
confusionMat, err := evaluation.GetConfusionMatrix(testData, predictions)
if err != nil {
panic(fmt.Sprintf("Unable to get confusion matrix: %s", err.Error())) //ERROR CAUSED HERE DUE TO GETTING <NIL>
}
fmt.Println(evaluation.GetSummary(confusionMat))
}