analytics~ ActiveLearner
Source: analyticsdoc.
Active learner. Uses a SVM model and implements an uncertainty measure (distance to the margin) to select which unlabelled example should be labelled next.
Methods
new ActiveLearner([arg])
Example
// load libs
var qm = require('qminer');
var la = qm.la;
// create model
var al = new qm.analytics.ActiveLearner();
// set data (4 labelled and 2 unlabelled examples)
var X = new la.Matrix([
[-2, 1],
[-2, 0],
[-2, -1],
[0, 1],
[-0.9, 0],
[0, -1]
]).transpose(); // column examples
al.setX(X);
var y = [-1, 0, -1, 1, 0, 1];
al.sety(y);
// get the array containing 1 index of the unlabelled example
// that is the closest to the hyperplane
var qidx = al.getQueryIdx(1);
console.log(qidx); // 4
Parameter
Name | Type | Optional | Description |
---|---|---|---|
arg |
|
Yes |
Construction arguments (JSON) or when loading: an input stream (fs.FIn) or a file name (string). |
Methods
_assertLabel()
Asserts if a label and the index are valid, given number of examples cols
_assertLabelSet()
Asserts if a Map with labels is valid
_assertMatrix()
Asserts if the object is a la matrix
_getDefaultSettings()
Returns default settings
_getLabArr()
Returns an array of label values corresponding to the labelled examples
_getLabelMapFromArr()
Transforms an Array of labels to a Map from indices to labels
_getLabIdxArr()
Returns an array of indices of labelled examples
_getQueryIdx(X, y, SVC[, num]) → Array of number
Return an array of indices where the model has the highest uncertainty (1 element by default)
Parameters
Name | Type | Optional | Description |
---|---|---|---|
X |
|
data matrix (column examples) |
|
y |
Map |
|
a Map from indices to 1 or -1 |
SVC |
|
a SVC model |
|
num |
number |
Yes |
the length of the array that is returned (top Defaults to |
- Returns
-
Array of number
B - array of indices of unlabelled examples
_getUnlabIdxArr()
Returns an array of indices of unlabelled examples
_retrain(X, y, SVC)
Retrains the SVC model
Parameters
Name | Type | Optional | Description |
---|---|---|---|
X |
|
data matrix (column examples) |
|
y |
Map |
|
a Map from indices to 1 or -1 |
SVC |
|
a SVC model |
getQueryIdx([num]) → Array of number
Returns an array of 0 or more example indices sorted by uncertainty (first element is the closest to the hyperplane)
Parameter
Name | Type | Optional | Description |
---|---|---|---|
num |
number |
Yes |
maximal length of the array Defaults to |
- Returns
-
Array of number
B array of unlabelled example indices
getSVC() → module:analytics.SVC
Returns the SVC model
- Returns
-
module:analytics.SVC
B SVC model
getX() → (module:la.Matrix or module:la.SparseMatrix)
Returns the data matrix (column examples)
- Returns
-
(module:la.Matrix or module:la.SparseMatrix)
B data matrix (column examples)
gety() → Map
Returns the Map from example indices to labels (-1 or 1)
- Returns
-
Map
B label map
load(input)
Loads instance matrix, labels and the model from the input stream
Parameter
Name | Type | Optional | Description |
---|---|---|---|
input |
(string or module:fs.FIn) |
|
a file name or an input stream |
retrain()
Retrains the SVC model
save(output)
Saves the instance matrix, labels and the model to the input stream
Parameter
Name | Type | Optional | Description |
---|---|---|---|
output |
(string or module:fs.FOut) |
|
a file name or an output stream |
setLabel(idx, label)
Sets the label
Parameters
Name | Type | Optional | Description |
---|---|---|---|
idx |
number |
|
instance index |
label |
number |
|
should be either 1 or -1 |
setX(X)
Sets the data matrix (column examples)
Parameter
Name | Type | Optional | Description |
---|---|---|---|
X |
|
data matrix (column examples) |
sety(_y)
Sets the labels
Parameter
Name | Type | Optional | Description |
---|---|---|---|
_y |
(Array of number, module.la.Vector, module.la.IntVector, or Map) |
|
array (like) object that encodes labels (-1, 0 or 1) or a Map from indices to 1 or -1 |