You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was testing the following go snippet in which I just train and test a knn model, and then load the same model and run inference again on the test data and the results are not the same. The confusion matrices of the model1 and 2 are just different.
to test the code you can get "iris_headers.csv" with wget https://raw.githubusercontent.com/sjwhitworth/golearn/master/examples/datasets/iris_headers.csv
Saved ad loaded model should give the exact same result, how can I fix this behavior?
package main
import (
"fmt""github.com/sjwhitworth/golearn/base"// did go get github.com/sjwhitworth/golearn/[email protected]"github.com/sjwhitworth/golearn/evaluation""github.com/sjwhitworth/golearn/knn"
)
funcmain() {
save_path:="saved_knn_9"fmt.Println("Load our csv data")
rawData, err:=base.ParseCSVToInstances("iris_headers.csv", true)
iferr!=nil {
panic(err)
}
fmt.Println("Initialize a new KNN classifier")
cls:=knn.NewKnnClassifier("euclidean", "linear", 2)
cls.AllowOptimisations=falsetrainData, testData:=base.InstancesTrainTestSplit(rawData, 0.60)
cls.Fit(trainData)
predictions, err:=cls.Predict(testData)
iferr!=nil {
panic(err)
}
fmt.Println("Print our summary metrics")
confusionMat, err:=evaluation.GetConfusionMatrix(testData, predictions)
iferr!=nil {
panic(fmt.Sprintf("Unable to get confusion matrix: %s", err.Error()))
}
fmt.Println(evaluation.GetSummary(confusionMat))
// saving the model to a filecls.Save(save_path)
// trying to load the model again.another_cls, err:=knn.ReloadKNNClassifier(save_path)
cls.AllowOptimisations=falseiferr!=nil {
panic(err)
}
fmt.Println("##### USING LOADED MODEL")
predictions2, err:=another_cls.Predict(testData)
iferr!=nil {
panic(err)
}
fmt.Println("Print our summary metrics of loaded model")
confusionMat2, err:=evaluation.GetConfusionMatrix(testData, predictions2)
iferr!=nil {
panic(fmt.Sprintf("Unable to get confusion matrix: %s", err.Error()))
}
fmt.Println(evaluation.GetSummary(confusionMat2))
}
This is the terminal output I got for one of my runs:
I was testing the following go snippet in which I just train and test a knn model, and then load the same model and run inference again on the test data and the results are not the same. The confusion matrices of the model1 and 2 are just different.
to test the code you can get "iris_headers.csv" with
wget https://raw.githubusercontent.com/sjwhitworth/golearn/master/examples/datasets/iris_headers.csv
Saved ad loaded model should give the exact same result, how can I fix this behavior?
This is the terminal output I got for one of my runs:
The text was updated successfully, but these errors were encountered: