How to use the analytics.js.newFeatureSpace function in analytics

To help you get started, we’ve selected a few analytics 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 / javascript_deprecated / src / timeseries.js View on Github external
if (line == "") { continue; }
	try {
		var vals = line.split(',');
		var rec = { "Time": vals[1], "Value": parseFloat(vals[0]) };
		var length = TimeSeries.length;
		assert.equals(TimeSeries.add(rec), length, "TimeSeries.add(rec)");
		assert.exists(TimeSeries[length], "TimeSeries[length]");
	} catch (err) { 
		console.say("TimeSeries", err);
	}
}

// test feature construction
var analytics = require('analytics.js');
// new feature space
var ftrSpace = analytics.newFeatureSpace([
	{ type: "numeric", source: "Resampled", field: "Value" },
	{ type: "numeric", source: "Resampled", field: "Ema" }
]);
assert.exists(ftrSpace, "ftrSpace");

for (var i = 0; i < Resampled.length; i++) {
	var rec = Resampled[i];
	var vec = ftrSpace.ftrVec(rec);
	assert.exists(vec, "ftrSpace.ftrVec(rec)");
}
github qminer / qminer / test / javascript_deprecated / src / ftrSpace.js View on Github external
t = t.sort(sortNumber);
    } else {
      p = p.sort();
      t = t.sort();
    }
    console.log("predicted/true");
    console.log(p);
    console.log(p.length);
    console.log(t);
    console.log(t.length);
  }
}

var newText = "I like ngrams and tests";
var testRec = Store.newRec({Value: 2.0, Category: "b", Categories: ["b", "w"], Text: newText });
var ftrSpace1 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", ngrams:[1,3], tokenizer:{type:'simple', stopwords: 'none'} },
]);
var trueAnswer = ['I', 'I LIKE', 'I LIKE NGRAMS', 'LIKE', 'LIKE NGRAMS', 'LIKE NGRAMS AND', 'NGRAMS', 'NGRAMS AND', 'NGRAMS AND TESTS', 'AND', 'AND TESTS', 'TESTS']; 
ftrSpace1.updateRecords(Store.recs);
ftrSpace1.updateRecord(testRec);
var vec = ftrSpace1.ftrSpVec(testRec);
var testAnswer = la.getSpFeatVecCols(vec, ftrSpace1);
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams 1,3");
printError(testAnswer, trueAnswer);

var ftrSpace2 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'} },
]);
trueAnswer = ['I', 'LIKE', 'NGRAMS', 'AND', 'TESTS'];
github qminer / qminer / test / javascript / src / ftrSpace.js View on Github external
//vec.print();
    }
}

function compareFtrSpace(ftrSpace1, ftrSpace2) {
    for (var i = 0; i < Store.length; i++) {
        var rec = Store[i];
        var vec1 = ftrSpace1.ftrVec(rec);
        var vec2 = ftrSpace2.ftrVec(rec);
        console.log("Diff: " + vec1.minus(vec2).norm());
    }
}

console.log("Prepare feature space");
var analytics = require("analytics.js");
var ftrSpace1 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "numeric", source: "FtrSpaceTest", field: "Value" },
    { type: "categorical", source: "FtrSpaceTest", field: "Category", values: ["a", "b", "c"] },
    { type: "categorical", source: "FtrSpaceTest", field: "Category", hashDimension: 2 },
    { type: "multinomial", source: "FtrSpaceTest", field: "Categories", values: ["a", "b", "c", "q", "w", "e"] },
    { type: "multinomial", source: "FtrSpaceTest", field: "Categories", hashDimension: 4 },
    { type: "text", source: "FtrSpaceTest", field: "Text", hashDimension: 4 },
    { type: "pair", source: "FtrSpaceTest",
        first: { type: "categorical", source: "FtrSpaceTest", field: "Category", values: ["a", "b", "c"] },
        second: { type: "multinomial", source: "FtrSpaceTest", field: "Categories", values: ["a", "b", "c", "q", "w", "e"] }
    }
]);
ftrSpace1.updateRecords(Store.recs);
console.log("Test new feature space");
testFtrSpace(ftrSpace1);
github qminer / qminer / test / javascript_deprecated / src / ftrSpace.js View on Github external
printError(testAnswer, trueAnswer);

var ftrSpace4 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'}, ngrams:[2,4], hashDimension: 320},
]);
trueAnswer = [ 239, 183, 57, 274, 266, 153, 257, 200, 8 ];
trueAnswer = trueAnswer.map(function(n) { return n.toString(); });
ftrSpace4.updateRecords(Store.recs);
ftrSpace4.updateRecord(testRec);
vec = ftrSpace4.ftrSpVec(testRec);
testAnswer = la.getSpFeatVecCols(vec, ftrSpace4);
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams 2, 4 with hashing");
printError(testAnswer, trueAnswer);

var ftrSpace5 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'},
     ngrams:[2,4], hashDimension: 320, hashTable: true},
]);
trueAnswer = ["OTHER VOLATILE", "UNIT TO", "DEPTHS OF", "WHEN BARBIE SETTLED", "I LIKE"];

ftrSpace5.updateRecords(Store.recs);
ftrSpace5.updateRecord(testRec);
testAnswer = ftrSpace5.getFtr(239).split(",");
assert.ok(arraysIdentical(testAnswer, trueAnswer), "hashing with tables");
printError(testAnswer, trueAnswer);
github qminer / qminer / test / javascript_deprecated / src / ftrSpace.js View on Github external
}
}

function compareFtrSpace(ftrSpace1, ftrSpace2) {
    for (var i = 0; i < Store.length; i++) {
        var rec = Store[i];
        var vec1 = ftrSpace1.ftrVec(rec);
        var vec2 = ftrSpace2.ftrVec(rec);
        console.log("Diff: " + vec1.minus(vec2).norm());
        
    }
}

console.log("Prepare feature space");
var analytics = require("analytics.js");
var ftrSpace1 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "numeric", source: "FtrSpaceTest", field: "Value" },
    { type: "dateWindow", source: "FtrSpaceTest", field: "Date", window: 3, unit: "12hours", normalize: true },
    { type: "categorical", source: "FtrSpaceTest", field: "Category", values: ["a", "b", "c"] },
    { type: "categorical", source: "FtrSpaceTest", field: "Category", hashDimension: 2 },
    { type: "multinomial", source: "FtrSpaceTest", field: "Categories", values: ["a", "b", "c", "q", "w", "e"] },
    { type: "multinomial", source: "FtrSpaceTest", field: "Categories", hashDimension: 4 },
    { type: "text", source: "FtrSpaceTest", field: "Text", hashDimension: 4, ngrams:[1,4] },
    { type: "pair", source: "FtrSpaceTest",
        first: { type: "categorical", source: "FtrSpaceTest", field: "Category", values: ["a", "b", "c"] },
        second: { type: "multinomial", source: "FtrSpaceTest", field: "Categories", values: ["a", "b", "c", "q", "w", "e"] }
    }
]);
ftrSpace1.updateRecords(Store.recs);
console.log(ftrSpace1.dim + " - " + JSON.stringify(ftrSpace1.dims));
console.log("Test new feature space");
github qminer / qminer / test / javascript_deprecated / src / ftrSpace.js View on Github external
var newText = "I like ngrams and tests";
var testRec = Store.newRec({Value: 2.0, Category: "b", Categories: ["b", "w"], Text: newText });
var ftrSpace1 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", ngrams:[1,3], tokenizer:{type:'simple', stopwords: 'none'} },
]);
var trueAnswer = ['I', 'I LIKE', 'I LIKE NGRAMS', 'LIKE', 'LIKE NGRAMS', 'LIKE NGRAMS AND', 'NGRAMS', 'NGRAMS AND', 'NGRAMS AND TESTS', 'AND', 'AND TESTS', 'TESTS']; 
ftrSpace1.updateRecords(Store.recs);
ftrSpace1.updateRecord(testRec);
var vec = ftrSpace1.ftrSpVec(testRec);
var testAnswer = la.getSpFeatVecCols(vec, ftrSpace1);
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams 1,3");
printError(testAnswer, trueAnswer);

var ftrSpace2 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'} },
]);
trueAnswer = ['I', 'LIKE', 'NGRAMS', 'AND', 'TESTS'];
ftrSpace2.updateRecords(Store.recs);
ftrSpace2.updateRecord(testRec);
vec = ftrSpace2.ftrSpVec(testRec);
testAnswer = la.getSpFeatVecCols(vec, ftrSpace2);
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams default (1)");
printError(testAnswer, trueAnswer);

var ftrSpace3 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'}, ngrams:[2,4]},
]);
trueAnswer = ['I LIKE', 'I LIKE NGRAMS', 'I LIKE NGRAMS AND', 'LIKE NGRAMS', 'LIKE NGRAMS AND', 'LIKE NGRAMS AND TESTS', 'NGRAMS AND', 'NGRAMS AND TESTS', 'AND TESTS'];
github qminer / qminer / test / javascript_deprecated / src / ftrSpace.js View on Github external
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams default (1)");
printError(testAnswer, trueAnswer);

var ftrSpace3 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'}, ngrams:[2,4]},
]);
trueAnswer = ['I LIKE', 'I LIKE NGRAMS', 'I LIKE NGRAMS AND', 'LIKE NGRAMS', 'LIKE NGRAMS AND', 'LIKE NGRAMS AND TESTS', 'NGRAMS AND', 'NGRAMS AND TESTS', 'AND TESTS'];
ftrSpace3.updateRecords(Store.recs);
ftrSpace3.updateRecord(testRec);
vec = ftrSpace3.ftrSpVec(testRec);
testAnswer = la.getSpFeatVecCols(vec, ftrSpace3);
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams 2, 4");
printError(testAnswer, trueAnswer);

var ftrSpace4 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'}, ngrams:[2,4], hashDimension: 320},
]);
trueAnswer = [ 239, 183, 57, 274, 266, 153, 257, 200, 8 ];
trueAnswer = trueAnswer.map(function(n) { return n.toString(); });
ftrSpace4.updateRecords(Store.recs);
ftrSpace4.updateRecord(testRec);
vec = ftrSpace4.ftrSpVec(testRec);
testAnswer = la.getSpFeatVecCols(vec, ftrSpace4);
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams 2, 4 with hashing");
printError(testAnswer, trueAnswer);

var ftrSpace5 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'},
     ngrams:[2,4], hashDimension: 320, hashTable: true},
github qminer / qminer / test / javascript_deprecated / src / ftrSpace.js View on Github external
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams 1,3");
printError(testAnswer, trueAnswer);

var ftrSpace2 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'} },
]);
trueAnswer = ['I', 'LIKE', 'NGRAMS', 'AND', 'TESTS'];
ftrSpace2.updateRecords(Store.recs);
ftrSpace2.updateRecord(testRec);
vec = ftrSpace2.ftrSpVec(testRec);
testAnswer = la.getSpFeatVecCols(vec, ftrSpace2);
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams default (1)");
printError(testAnswer, trueAnswer);

var ftrSpace3 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'}, ngrams:[2,4]},
]);
trueAnswer = ['I LIKE', 'I LIKE NGRAMS', 'I LIKE NGRAMS AND', 'LIKE NGRAMS', 'LIKE NGRAMS AND', 'LIKE NGRAMS AND TESTS', 'NGRAMS AND', 'NGRAMS AND TESTS', 'AND TESTS'];
ftrSpace3.updateRecords(Store.recs);
ftrSpace3.updateRecord(testRec);
vec = ftrSpace3.ftrSpVec(testRec);
testAnswer = la.getSpFeatVecCols(vec, ftrSpace3);
assert.ok(arraysIdentical(testAnswer, trueAnswer), "ngrams 2, 4");
printError(testAnswer, trueAnswer);

var ftrSpace4 = analytics.newFeatureSpace([
    //{ type: "random", source: "FtrSpaceTest", seed: 1 },
    { type: "text", source: "FtrSpaceTest", field: "Text", tokenizer:{type:'simple', stopwords: 'none'}, ngrams:[2,4], hashDimension: 320},
]);
trueAnswer = [ 239, 183, 57, 274, 266, 153, 257, 200, 8 ];