sjwhitworth / golearn

Machine Learning for Go
MIT License
9.3k stars 1.19k forks source link

Saving Model #218

Open rob-otter-is19 opened 6 years ago

rob-otter-is19 commented 6 years ago

I was experimenting with the randomforest in the ensemble package: The code (a little bit simplified) looks like this:

forest := ensemble.NewRandomForest(trees, features)
forest.Fit(trainData)
predictions, err := forest.Predict(testData)
....
err = forest.Save(modelFile)
....
currentForest := ensemble.NewRandomForest(trees, features)
err = currentForest.Load(modelFile)
predictionsCurrent, err := currentForest.Predict(testData)

fmt.Println(currentForest)

When i save the forest a file is made. But when i load the Forest and print it the BaggedModel() is empty. I was first recognizing it when i tried to load the model and make predictions with the same TestData -> i think there should be the same accuracy but its not. Also the Confusion Matrix shows 2 fields with NaN.

Is there another way to save and restore the model or am i doing anything wrong?

Sentimentron commented 6 years ago

The code looks OK, investigating...

On Tue, 27 Nov 2018 at 08:03, Rob Otter notifications@github.com wrote:

I was experimenting with the randomforest in the ensemble package: The code (a little bit simplified) looks like this:

forest := ensemble.NewRandomForest(trees, features) forest.Fit(trainData) predictions, err := forest.Predict(testData) .... err = forest.Save(modelFile) .... currentForest := ensemble.NewRandomForest(trees, features) err = currentForest.Load(modelFile) predictionsCurrent, err := currentForest.Predict(testData)

fmt.Println(currentForest)

When i save the forest a file is made. But when i load the Forest and print it the BaggedModel() is empty. I was first recognizing it when i tried to load the model and make predictions with the same TestData -> i think there should be the same accuracy but its not. Also the Confusion Matrix shows 2 fields with NaN.

Is there another way to save and restore the model or am i doing anything wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sjwhitworth/golearn/issues/218, or mute the thread https://github.com/notifications/unsubscribe-auth/ADiPOVRKY8bRefMZB9VRGmOmCxkrsbbEks5uzPHogaJpZM4Y07fl .

-- Sent from my iPhone

hajians commented 5 years ago

I have similar issue. While investigating quickly the source code I saw that the Save function uses GetMetadata() method. When I invoke it on a RandomForest instance that is trained I get: {1 KNN 1.0 map[]}. Could this be the issue?

lnashier commented 5 years ago

Is it still an issue ?

rjzak commented 4 years ago

It's an issue for LogisticRegression.

type LogisticRegression struct {
    param *Parameter
    model *Model
  }

The function to save the model is: func Export(model *Model, filePath string) error. However, the user can't access the *Model parameter.

zhengcongyin commented 4 years ago

I saved an ID3 tree model and attempted to load it. It returned the error message

GoLearnError( Error reading CLS_MANIFEST: unexpected EOF )

not sure if it is related to the above issues.