Skip to content

Online models

Variadic function definitions in the KX Insights ML-Analytics library for the out-of-core models in the library

.ml.kxi.online. clust.sequentialKMeans.fit fit a Sequential K Means model sgd.linearRegression.fit fit an Online Linear Regression model sgd.logClassifier.fit fit an Online Logistic Classification model

This abstraction is provided as a novice user’s entry point to these models, with the full interface provided as a callable function to facilitate greater control for users who require broader control over model fitting.

.ml.kxi.online.clust.sequentialKMeans.fit

Fit a Sequential K Means model

.ml.kxi.online.clust.sequentialKMeans.fit[X]
.ml.kxi.online.clust.sequentialKMeans.fit[X;config]

Where

  • X is the input/training data
  • config is an optional dictionary containing modifications to default behavior, with keys

    key type default description
    df symbol e2dist Distance function used in calculating distance between cluster centers and data points
    k integer 8 Number of cluster centers to be calculated
    centers dictionary :: Initial cluster centers, if :: then these are calculated automatically, if defined otherwise this seeds the initial cluster if provided with the number of items per cluster (num) and the centroids of these clusters (centroids).
    config dictionary :: Any additional configuration required for application of clustering, supported options defined here.

returns a dictionary

modelInfo | all information needed to fit the original model 
predict   | a projection allowing for predictions on new input data 
update    | a projection allowing new data to be used to update cluster centers 
            such that the model can react to new data
q)data:([]100?1f;100?1f)

// Fit a model using default configuration
q)show mdl1:.ml.kxi.online.clust.sequentialKMeans.fit data
modelInfo| `num`centroids`inputs!(12 12 17 16 9 10 18 6;(0.7707787 0.3010448 ..
predict  | {[returnInfo;data]
  modelInfo:returnInfo`modelInfo;
  data:clust...
update   | {[returnInfo;data]
  modelInfo:returnInfo`modelInfo;
  inputs:mode..
q)mdl1`modelInfo
num      | 12 12 17 16 9 10 18 6
centroids| (0.7707787 0.3010448 0.9010772 0.8386579 0.2017322 0.2366765 0.375..
inputs   | `df`k`config!(`e2dist;8;`init`a`forgetful!(1b;0.1;1b))

// Fit a model modifying the default behavior
q)show mdl2:.ml.kxi.online.clust.sequentialKMeans.fit[data;`df`k!(`edist;3)]
modelInfo| `num`centroids`inputs!(36 20 44;(0.6453533 0.8516896 0.3043771;0.8..
predict  | {[returnInfo;data]
  modelInfo:returnInfo`modelInfo;
  data:clust...
update   | {[returnInfo;data]
  modelInfo:returnInfo`modelInfo;
  inputs:mode..
q)mdl2`modelInfo
num      | 36 20 44
centroids| (0.6453533 0.8516896 0.3043771;0.8094041 0.2191981 0.4397323)
inputs   | `df`k`config!(`edist;3;`init`a`forgetful!(1b;0.1;1b))

.ml.kxi.online.sgd.linearRegression.fit

Fit an Online Linear Regression model

.ml.kxi.online.sgd.linearRegression.fit[X;y]
.ml.kxi.online.sgd.linearRegression.fit[X;y;config]

Where

  • X is the input/training data
  • y are the expected predictions
  • config is an optional dictionary containing modifications to default behavior, with keys

    key type default description
    trend boolean 1b Does the model expect a trend to be accounted for in fitting
    config dictionary :: Any additional configuration required for application of regression, supported options defined here.

returns a dictionary

modelInfo    | all information needed to fit the original model 
predict      | a projection allowing for predictions on new input data 
update       | a projection allowing new data to be used to update regression parameters 
               such that the model can react to new data 
updateSecure | a projection allowing new data to be used to update regression parameters 
               such that the model can react to new data 
q)data:([]100?1f;asc 100?1f)
q)target:asc 100?1f

// Fit a model using default configuration
q)show mdl1:.ml.kxi.online.sgd.linearRegression.fit[data;target]
modelInfo   | `theta`iter`diff`trend`paramDict`inputType!(0.2696617 0.0185797..
predict     | {[config;features]
  config:config`modelInfo;
  if[config`trend..
update      | {[config;secure;features;target]
  modelInfo:config`modelInfo;
..
updateSecure| {[config;secure;features;target]
  modelInfo:config`modelInfo;
..

// Fit a model modifying the default behavior
q)config:`alpha`l1Ratio`verbose!(0.02;0.4;1b)
q)show mdl2:.ml.kxi.online.sgd.linearRegression.fit[data;target;`trend`config!(1b;config)]
modelInfo   | `theta`iter`diff`trend`paramDict`inputType!(0.2186998 0.0084106..
predict     | {[config;features]
  config:config`modelInfo;
  if[config`trend..
update      | {[config;secure;features;target]
  modelInfo:config`modelInfo;
..
updateSecure| {[config;secure;features;target]
  modelInfo:config`modelInfo;
..
q)mdl2`modelInfo
theta    | 0.2186998 0.008410636 0.7844071
iter     | 37
diff     | 7.442356e-06 -7.282613e-06 -8.801685e-06
trend    | 1b
paramDict| `alpha`maxIter`gTol`theta`k`seed`batchType`gradArgs`penalty`lambda..
inputType| (+(,`c)!,`x`x1)!+`t`f`a!("ff";``;``s)

.ml.kxi.online.sgd.logClassifier.fit

Fit an Online Logistic Classification model

.ml.kxi.online.sgd.logClassifier.fit[X;y]
.ml.kxi.online.sgd.logClassifier.fit[X;y;config]

Where

  • X is the input/training data
  • y are the expected predictions
  • config is an optional dictionary containing modifications to default behavior, with keys

    Key Type Default Description
    trend boolean 1b Does the model expect a trend to be accounted for in fitting
    config dictionary :: Any additional configuration required for application of regression, supported options defined here.

returns a dictionary

modelInfo    | all information needed to fit the original model 
predict      | a projection allowing for predictions on new input data 
update       | a projection allowing new data to be used to update regression parameters 
               such that the model can react to new data 
updateSecure | a projection allowing new data to be used to update regression parameters
               such that the model can react to new data 
q)data:([]100?1f;asc 100?1f)
q)target:asc 100?7

// Fit a model using default configuration
q)show mdl1:.ml.kxi.online.sgd.logClassifier.fit[data;target]
modelInfo   | `theta`iter`diff`trend`paramDict`inputType!((-1.713844 -1.71962..
predict     | {[config;features]
  yhat:.sgd.linearRegression.predict[c..
update      | {[config;secure;features;target]
  modelInfo:config`modelInfo;
..
updateSecure| {[config;secure;features;target]
  modelInfo:config`modelInfo;
..
q)mdl1`modelInfo
theta    | (-1.713844 -1.719627 -1.711246 -1.712292 -1.722998 -1.719939 -1.71..
iter     | 100
diff     | (0.006921089 0.006989055 0.006892948 0.006904046 0.00702937 0.0069..
trend    | 1b
paramDict| `alpha`maxIter`gTol`theta`k`seed`batchType`gradArgs`penalty`lambda..
inputType| (+(,`c)!,`x`x1)!+`t`f`a!("ff";``;``s)

// Fit a model modifying the default behavior
q)config:`alpha`seed!(0.02;42)
q)show mdl2:.ml.kxi.online.sgd.logClassifier.fit[data;target;`trend`config!(1b;config)]
modelInfo   | `theta`iter`diff`trend`paramDict`inputType!(0.2186998 0.0084106..
predict     | {[config;features]
  config:config`modelInfo;
  if[config`trend..
update      | {[config;secure;features;target]
  modelInfo:config`modelInfo;
..
updateSecure| {[config;secure;features;target]
  modelInfo:config`modelInfo;
..
q)mdl2`modelInfo
theta    | (0.604462 -0.488939 -1.442066 -2.16019 -2.174752 -2.893451 -4.3947..
iter     | 100
diff     | (-0.006845301 -0.003737216 0.0005487501 0.003565864 0.004461997 0...
trend    | 1b
paramDict| `alpha`maxIter`gTol`theta`k`seed`batchType`gradArgs`penalty`lambda..
inputType| (+(,`c)!,`x`x1)!+`t`f`a!("ff";``;``s)