How to use the qminer.analytics.PCA function in qminer

To help you get started, we’ve selected a few qminer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qminer / qminer / test / nodejs / exampleanalyticsdoc.js View on Github external
it("should make test number 101", function () {

         // import analytics module
         var analytics = require('qminer').analytics;
         // construct model
         var pca = new analytics.PCA();
         // create matrix
         var matrix = new la.Matrix([[0, 1], [-1, 0]]);
         // fit the matrix
         pca.fit(matrix);
        
});
});
github qminer / qminer / test / nodejs / pca.js View on Github external
it("should throw an exception because k is bigger than matrix dimensions", function () {
            var pca = new analytics.PCA({ k: 5 });
            var matrix = new la.Matrix([[1, -1], [0, 0]]);
            /*if (require('qminer').flags.blas) {	// XXX WTF!? why is this here, the same logic is tested for different behaviour
                assert.doesNotThrow(function () {
                    pca.fit(matrix);
                });
            } else {*/
                assert.throws(function () {
                    pca.fit(matrix);
                });
//            }
        });
        it("should return the model parameters after using fit", function () {
github qminer / qminer / test / nodejs / exampleanalyticsdoc.js View on Github external
it("should make test number 97", function () {

         // import analytics module
         var analytics = require('qminer').analytics;
         // construct model
         var pca = new analytics.PCA();
         // create matrix
         var matrix = new la.Matrix([[0, 1], [-1, 0]]);
         // fit matrix
         pca.fit(matrix);
         var model = pca.getModel();
         // save model
         pca.save(require('qminer').fs.openWrite('pca_test.bin')).close();
        
});
});
github qminer / qminer / test / nodejs / exampleanalyticsdoc.js View on Github external
it("should make test number 99", function () {

         // import analytics module
         var analytics = require('qminer').analytics;
         // construct model
         var pca = new analytics.PCA();
         // check the constructor parameters
         var paramvalue = pca.getParams();
        
});
});
github qminer / qminer / test / nodejs / exampleanalyticsdoc.js View on Github external
it("should make test number 100", function () {

         // import analytics module
         var analytics = require('qminer').analytics;
         // construct model
         var pca = new analytics.PCA();
         // set parameters
         pca.setParams({iter: 10, k: 5});
         // check the changed parameters
         var paramvalue = pca.getParams();
        
});
});
github qminer / qminer / test / nodejs / exampleanalyticsdoc.js View on Github external
it("should make test number 98", function () {

         // import analytics module
         var analytics = require('qminer').analytics;
         // construct model
         var pca = new analytics.PCA();
         // set 5 eigenvectors and 10 iterations using setParams
         pca.setParams({iter: 10, k: 5});
        
});
});
github qminer / qminer / test / nodejs / pca.js View on Github external
it("should return changed values of parameters", function () {
            var pca = new analytics.PCA();
            pca.setParams({ iter: 10, k: 5 });
            var params = pca.getParams();
            assert.equal(params.iter, 10);
            assert.equal(params.k, 5);
        });
        it("should return changed values of parameters, ignoring added key values", function () {
github qminer / qminer / test / nodejs / pca.js View on Github external
it("should return values of parameters and added keys", function () {
            var pca = new analytics.PCA({ iter: 30, alpha: 3 });
            var params = pca.getParams();
            assert.equal(params.iter, 30);
            assert.equal(params.alpha, undefined);
        });
        it("should return empty model parameters", function () {
github qminer / qminer / test / nodejs / pca.js View on Github external
it("should throw and exception because matrix dimensions don't match", function () {
            var pca = new analytics.PCA();
            var matrix = new la.Matrix([[0, 1], [-1, 0], [2, -1]]);
            pca.fit(matrix);
            var newMatrix = new la.Matrix([[0, 1, 4], [-1, 0, 0]]);
            var model = pca.getModel();
            assert.throws(function () {
                pca.transform(newMatrix);
            });
        });
    });
github qminer / qminer / test / nodejs / pca.js View on Github external
it("should serialize and deserialize the model", function () {
            var pca = new analytics.PCA({ k: 1 });
            var matrix = new la.Matrix([[0, 1], [-1, 0]]);
            pca.fit(matrix);
            var model = pca.getModel();
            var tran = pca.transform(matrix);
            pca.save(require('qminer').fs.openWrite('pca_test.bin')).close();
            var pca2 = new analytics.PCA(require('qminer').fs.openRead('pca_test.bin'));
            var model2 = pca2.getModel();
            assert.deepEqual(pca.getParams(), pca2.getParams());
            assert.eqtol(model.mu.minus(model2.mu).norm(), 0);
            assert.eqtol(model.lambda.minus(model2.lambda).norm(), 0);
            assert.eqtol(model.P.minus(model2.P).frob(), 0);
        });
    });