Property

new TDigest([arg])

TDigest quantile estimation on streams

Example

// import modules
var qm = require('qminer');
var analytics = qm.analytics;
// create the default TDigest object
var tdigest = new analytics.TDigest();
// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];
// fit the TDigest model
for (var i = 0; i < inputs.length; i++) {
    tdigest.partialFit(inputs[i]);
}
// make the prediction for the 0.1 quantile
var prediction = tdigest.predict(0.1);
// save the model
tdigest.save(fs.openWrite('tdigest.bin')).close();
// open the tdigest model under a new variable
var tdigest2 = new analytics.TDigest(fs.openRead('tdigest.bin'));

Parameter

Name Type Optional Description

arg

(module:analytics~TDigestParam or module:fs.FIn)

Yes

Construction arguments. There are two ways of constructing:
1. Using the module:analytics~TDigestParam object,
2. using the file input stream module:fs.FIn.

Property

init

Returns true when the model has enough data to initialize. Type boolean.

Example

// import modules
var qm = require('qminer');
var analytics = qm.analytics;
var fs = qm.fs;
// create the default TDigest object
var tdigest = new analytics.TDigest();
// check if the model has enough data to initialize
if (tdigest.init) { console.log("Ready to initialize"); }

Methods

getParams() → module:analytics~TDigestParam

Returns the parameters.

Example

// import modules
var qm = require('qminer');
var analytics = qm.analytics;
// create the default TDigest object
var tdigest = new analytics.TDigest();
// get the parameters of the object
var params = tdigest.getParams();
Returns

module:analytics~TDigestParam The construction parameters.

partialFit(x) → module:analytics.TDigest

Adds a new measurement to the model and updates the approximation of the data distribution.

Example

// import modules
var qm = require('qminer');
var analytics = qm.analytics;
// create the default TDigest object
var tdigest = new analytics.TDigest();
// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];
// fit the TDigest model with all input values
for (var i = 0; i < inputs.length; i++) {
    tdigest.partialFit(inputs[i]);
}

Parameter

Name Type Optional Description

x

number

 

Input number.

Returns

module:analytics.TDigest Self. The model has been updated.

predict(x) → number

Returns a quantile given input number, that is the approximate fraction of samples smaller than the input (0.05 means that 5% of data is smaller than the input value).

Example

// import modules
var qm = require('qminer');
var analytics = qm.analytics;
// create the default TDigest object
var tdigest = new analytics.TDigest();
// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];
// fit the TDigest model
for (var i = 0; i < inputs.length; i++) {
    tdigest.partialFit(inputs[i]);
}
// make the prediction for the 0.1 quantile
var prediction = tdigest.predict(0.1);

Parameter

Name Type Optional Description

x

number

 

Input number.

Returns

number Quantile (between 0 and 1).

save(fout) → module:fs.FOut

Saves TDigest internal state into (binary) file.

Example

// import modules
var qm = require('qminer');
var analytics = qm.analytics;
var fs = qm.fs;
// create the default TDigest object
var tdigest = new analytics.TDigest();
// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];
// fit the TDigest model
for (var i = 0; i < inputs.length; i++) {
    tdigest.partialFit(inputs[i]);
}
// save the model
tdigest.save(fs.openWrite('tdigest.bin')).close();
// open the tdigest model under a new variable
var tdigest2 = new analytics.TDigest(fs.openRead('tdigest.bin'));

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

The output stream.

Returns

module:fs.FOut The output stream fout.

setParams(params) → module:analytics.TDigest

Sets the parameters.

Example

// import modules
var qm = require('qminer');
var analytics = qm.analytics;
// create the default TDigest object
var tdigest = new analytics.TDigest();
// set the parameters of the object
var params = tdigest.setParams({ minCount: 10, clusters: 50 });

Parameter

Name Type Optional Description

params

module:analytics~TDigestParam

 

The construction parameters.

Returns

module:analytics.TDigest Self. The model parameters have been updated.