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

No convergence #27

Closed
ricardopolo opened this issue Feb 15, 2016 · 5 comments
Closed

No convergence #27

ricardopolo opened this issue Feb 15, 2016 · 5 comments
Labels

Comments

@ricardopolo
Copy link
Contributor

Hello.

I am getting this error
node_modules/numeric/numeric-1.2.6.js:4340 throw 'Error: no convergence.'

I passed this data https://raw.githubusercontent.com/mailgun/talon/master/talon/signature/data/train.data
where the last position is the expected outcome.

This is the code that throws the error.

  fs.readFile('traineddata.txt', 'utf8', function(err, content){
    var train_data = [];
    S(content.trim()).lines().forEach(function(line){
      var spllited_line = line.split(',');
      supervisory_signal = spllited_line[spllited_line.length - 1];
      var vector = [];
      for (i = 0; i < spllited_line.length -1; i++) {
        vector.push(spllited_line[i]);
      }
      train_data.push([vector, supervisory_signal]);
    });
      var clf = new svm.SVM();
     clf.train(train_data).done(function () {
    var prediction = clf.predictSync(input);
  });
  });

Any advice about how can I fix it?

@nicolaspanel
Copy link
Owner

I think you are passing Strings instead of Numbers.

Something like this should work:

fs.readFile('traineddata.txt', 'utf8', function(err, content){
    var data = S(content.trim()).lines().map(function(line){
      line = line.split(',').map(function(item){ return parseFloat(item); });
      return [ line.slice(0,-1)  , line.slice(-1)[0]];
     });
      var clf = new svm.SVM();
     clf.train(data).done(function () {
    var prediction = clf.predictSync(input);
  }); 
});

@mjp0
Copy link

mjp0 commented Jul 3, 2016

I'm having this same issue. I've triple checked that all my numbers are actual numbers.

Here's my trainer code. At this point I'm just trying to get this library to do anything at all so I'm just copy/pasting from examples. Data is fetched from database so I'm not using svm.read() or similar functions.

const clf = new svm.EpsilonSVR({
    gamma: [0.125, 0.5, 1],
    c: [8, 16, 32],
    epsilon: [0.001, 0.125, 0.5],
    normalize: true, // (default)
    reduce: true, // (default)
    retainedVariance: 0.995,
    kFold: 5
});
clf.train(dataset)
        .progress(function(progress){
            console.log('training progress: %d%', Math.round(progress*100));
        })
        .spread(function (model, report) {
            console.log('SVM trained. \nReport :\n%s', so(report));
            return dataset;
        }).then(function (dataset) {
            // randomly pick m values and display predictions
            _a.pick(dataset, 5).forEach(function (ex, i) {
                var prediction = clf.predictSync(ex[0]);
                console.log(' { #%d, expected: %d, predicted: %d}',i+1, ex[1], prediction);
            });
        })
        .fail(function (err) {
            throw err;

        })
        .done(function () {
            console.log('done.');
        });

Here's what my dataset looks like:

[ [ [ 0.9370528277403535,
      1,
      10.2446782417689,
      0.1,
      0.2157508638191752,
      0.4,
      2.9547269278195842,
      0.6,
      5.305598923648802,
      0.7,
      14.080959534461057,
      0.8,
      16.787868319892056,
      0.9,
      9.33018890638979,
      0.2,
      0.6232436952147369,
      0.3,
      0.21013282524728893,
      0.5,
      3.74996578411525,
      0.06294717225964656,
      1,
      6.780877019575415,
      2,
      1.9003776435045472,
      2.1,
      10.242337961671112,
      1.6,
      6.317515476417146,
      1.5,
      12.969169488832977,
      1.3,
      12.570850329693071,
      1.2,
      2.327629391532482,
      0.9,
      5.074429387365065,
      0.7,
      3.3060673703062537,
      0.4,
      3.9453340184839814,
      0.1,
      0.15236271737872897,
      0.2,
      0.2373174670956546,
      0.3,
      0.8227919716677468,
      0.5,
      3.1718293970518285,
      0.6,
      2.89604238058212,
      0.8,
      1.5460014704966607,
      1.1,
      5.111847470474484,
      1.4,
      3.97480070903542,
      1.7,
      6.72969175025937,
      1.8,
      3.49031097535919,
      1.9,
      7.411393336684169 ],
    0 ],
  [ [ 0.9369869025261525,
      1,
      1.819219777880099,
      0.1,
      0.18802582343899754,
      0.3,
      0.8968994041430811,
      0.5,
      4.825678824413293,
      0.6,
      11.915415800114726,
      0.8,
      18.48834287306935,
      0.9,
      12.06725732683406,
      0.2,
      0.3907571402120391,
      0.4,
      2.336214726853436,
      0.7,
      6.502915428451727,
      0.06301309747384755,
      1,
      2.7389554182335907,
      1.7,
      6.555133166011573,
      1.6,
      7.556795774747793,
      1.4,
      9.463475271773756,
      1.2,
      1.1956521739130421,
      1.1,
      12.601448919248993,
      0.9,
      4.353193433215896,
      0.8,
      4.3536001430615645,
      0.5,
      5.420907071538794,
      0.1,
      0.25291109688767577,
      0.2,
      0.17735759446704247,
      0.3,
      1.3192241076551925,
      0.4,
      1.0979702653683976,
      0.6,
      3.265845573077364,
      0.7,
      3.2684995321619725,
      1.3,
      6.354655877994975,
      1.5,
      7.364235879648184,
      1.8,
      8.743032992838561,
      1.9,
      5.596492067848269 ],
    2 ] ]

@nicolaspanel
Copy link
Owner

Please check your data

@mjp0
Copy link

mjp0 commented Jul 3, 2016

@nicolaspanel check it for what?

@viorelzavoiu
Copy link

Don't know if this helps, but i had the same issue and I found out that there was a problem with the reduction part of the algorithm with PCA. The error appears in the Single Value Decomposition procedure. So to bypass the error I skipped the reduction step: { reduce : false }

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

No branches or pull requests

4 participants