Skip to content

Save and load a classifier #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jamesalbert
Copy link

Save and load a classifier to/from a binary file.

I had to make some of the attributes public to do this.

Example:

classifier := naive.New()
classifier.TrainString("The quick brown fox jumped over the lazy dog", "ham")
classifier.TrainString("Earn a degree online", "ham")
classifier.TrainString("Earn cash quick online", "spam")
classifier.Save("test.bin")

// ...later...

classifier, err := naive.Load("test.bin")
if classification, err := classifier.ClassifyString("Earn your masters degree online"); err == nil {
	fmt.Println("Classification => ", classification) // ham
} else {
	fmt.Println("error: ", err)
}

@jamesalbert
Copy link
Author

jamesalbert commented May 12, 2019

Should have tested this on real data 😉

While the provided example does work as expected, trying this on other data yields inconsistent results between pre-saved/post-loaded classifiers.

edit: I'm actually getting inconsistent results from the same test input whether or not I save. I would have thought it would give the same classification every time. I'm just an ML n00b and this is probably expected, at least with a small sample size

@n3integration
Copy link
Owner

Hey @jamesalbert - thanks for submitting the pull request. I had been meaning to add support for persistence, but hadn't had a chance; much appreciated. If you run the same exact data through every time, you should get the same results. If you're not, we have a problem. Is there any way that you can provide details about the data set that you're using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants