Skip to content
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

unable to predict from load previous model #34

Closed
BoChengHuang opened this issue May 28, 2016 · 8 comments
Closed

unable to predict from load previous model #34

BoChengHuang opened this issue May 28, 2016 · 8 comments

Comments

@BoChengHuang
Copy link

Hello, I train a data set and store it into other folder. (in index.js)
After that, I create a file called predict.js, main code is like:

var persistedModel = JSON.parse(fs.readFileSync('./model/poker_sim_test.json'));
var clf = new svm.NuSVC({ model: persistedModel });
var prediction = clf.predict(guess);

when I run it I face a problem that:

assert.js:89
throw new assert.AssertionError({
^
AssertionError: false == true
at NuSVC.SVM.predict (/Users/ives/Downloads/SVM_PokerHand/node_modules/node-svm/lib/core/svm.js:147:5)

How can I fix problems.

Thanks!!

@nicolaspanel
Copy link
Owner

nicolaspanel commented May 28, 2016

To restore an existing prediction model you should use svm.restore function.

Example:

var svm = require('node-svm');
var persistedModel = JSON.parse(fs.readFileSync('./model/poker_sim_test.json'));
var clf = svm.restore(persistedModel);

BR

@BoChengHuang
Copy link
Author

Thank you but I still face this...

assert.js:89
throw new assert.AssertionError({
^
AssertionError: false == true
at NuSVC.SVM.predict (/Users/ives/Downloads/SVM_PokerHand/node_modules/node-svm/lib/core/svm.js:147:5)

Thanks!!

@BoChengHuang
Copy link
Author

my test code is here, train and predict in a js file.

@nicolaspanel
Copy link
Owner

Try this instead:

nodesvm.read(pathToTrainingData).then(function (dataset) {
    var clf = new nodesvm.NU_SVC({
            kFold: 4,
            normalize: false,
            reduce: false,
            kernelType: 'RBF',
            gamma: [0.03125, 0.125, 0.5, 2, 8]
      });
      clf.train(dataset).spread(function (model, report) {
            fs.writeFileSync('./model/poker_sim_test.json', JSON.stringify(model));
      }).then(function(){
            var persistedModel = JSON.parse(fs.readFileSync('./model/poker_sim_test.json'));
            var restoredClf = nodesvm.restore(persistedModel);
            restoredClf.predictSync([4, 10, 4, 11, 4, 1, 4, 13, 4, 12]);
      });
});

@BoChengHuang
Copy link
Author

It seems to appear another error

Assertion failed: (elt->IsNumber()), function setModel, file ../src/node-svm/node-svm.h, line 229.
Abort trap: 6

my dataset is like this:
9 1:1 2:10 3:1 4:11 5:1 6:13 7:1 8:12 9:1 10:1
.
.
.

sorry for bothering
Thanks!

@nicolaspanel
Copy link
Owner

nicolaspanel commented May 28, 2016

it seems that this error comes from your dataset but I can't help you with that...

@BoChengHuang
Copy link
Author

Hello I can use the model from external file latter.

I originally use this and it can generate a model but can't predict as above discussion.

Latter I create a model file by 'node-svm train [train file] [model path]'.

And I use the sane dataset and the same prediction code, then everything works.

FYI

thank you!!!

@nicolaspanel
Copy link
Owner

Thank you for your feedback!
BR

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

No branches or pull requests

2 participants