Skip to content

Timeseries models

Variadic function definitions in the KX Insights ML-Analytics library for timeseries models

.ml.kxi.ts. AR.fit fit an AutoRegressive model ARMA.fit fit an AutoRegressive Moving model ARIMA.fit fit an AutoRegressive Integrated Moving model SARIMA.fit fit a Seasonal AutoRegressive Integrated Moving model

ML Toolkit timeseries algorithms for examples of function returns for prediction/update, not covered below

.ml.kxi.ts.AR.fit

Fit an AutoRegressive model

.ml.kxi.ts.AR.fit[endog;p]
.ml.kxi.ts.AR.fit[endog;p;config]

Where

  • endog is the numerical endogenous variable (a variable determined by its relationship with others)
  • p is the number of lags to include in model generation
  • config is an optional dictionary argument containing modifications to default behavior, with keys

    key type default description
    exog table float[] ::
    trend boolean 1b Is a trend to be accounted for in generation of the model

returns a dictionary

modelInfo | all information needed to fit the original model 
            and returned during the fitting process 
predict   | a projection allowing for predictions on new input data 
q)endog:100?1f
q)exog:10+100?1f

// Fit a model using default configuration
q)show mdl1:.ml.kxi.ts.AR.fit[endog;2]
modelInfo| `coefficients`trendCoeff`exogCoeff`pCoeff`lagVals!(0.5098695 0.130..
predict  | {[config;exog;len]
  model:config`modelInfo;
  exog:ts.i.predDataC..
q)mdl1`modelInfo
coefficients| 0.5098695 0.1308255 -0.1176227
trendCoeff  | ,0.5098695
exogCoeff   | `float$()
pCoeff      | 0.1308255 -0.1176227
lagVals     | 0.159069 0.2646864

// Fit a model modifying the default behavior
q)show mdl2:.ml.kxi.ts.AR.fit[endog;2;`exog`trend!(exog;0b)]
modelInfo| `coefficients`trendCoeff`exogCoeff`pCoeff`lagVals!(0.07857143 -0.6..
predict  | {[config;exog;len]
  model:config`modelInfo;
  exog:ts.i.predDataC..
q)mdl2`modelInfo
oefficients| 0.07857143 -0.6071429 1.45
trendCoeff  | `float$()
exogCoeff   | ,0.07857143
pCoeff      | -0.6071429 1.45
lagVals     | 8 9f

.ml.kxi.ts.ARIMA.fit

Fit an AutoRegressive Integrated Moving Average model

.ml.kxi.ts.ARIMA.fit[endog]
.ml.kxi.ts.ARIMA.fit[endog;config]

Where

  • endog is the numerical endogenous variable (variable determined by its relationship with others)
  • config is an optional dictionary argument containing modifications to default behavior, with keys

    key type default description
    exog table float[] ::
    p long 0 Is the number of lags to include in model generation
    q long 0 Is the number of residual errors to include in model generation
    d long 0 Is the number of differencing terms to include in model generation
    trend boolean 1b Is a trend to be accounted for in generation of the model

returns a dictionary

modelInfo | all information needed to fit the original model 
            and returned during the fitting process 
predict   | a projection allowing for predictions on new input data 
q)endog:100?1f
q)exog:10+100?1f

// Fit a model using default configuration
q)show mdl1:.ml.kxi.ts.ARIMA.fit[endog]
modelInfo| `coefficients`trendCoeff`exogCoeff`pCoeff`lagVals`qCoeff`residualV..
predict  | {[config;exog;len]
  model:config`modelInfo;
  exog:ts.i.predDataC..
q)mdl1`modelInfo
coefficients  | ,0.4955508
trendCoeff    | ,0.4955508
exogCoeff     | `float$()
pCoeff        | `float$()
lagVals       | `float$()
qCoeff        | ()
residualVals  | ()
residualCoeffs| ()
paramDict     | `p`q`trend!(0;0;1b)
originalData  | `float$()

// Fit a model modifying the default behavior
q)show mdl2:.ml.kxi.ts.ARIMA.fit[endog;`exog`p`d`q!(exog;5;2;2)]
modelInfo| `coefficients`trendCoeff`exogCoeff`pCoeff`qCoeff`lagVals`residualV..
predict  | {[config;exog;len]
  model:config`modelInfo;
  exog:ts.i.predDataC..
q)mdl2`modelInfo
coefficients  | -0.4041469 0.03772791 -0.1416746 -0.2788988 -0.2048458 -0.535..
trendCoeff    | -0.4041469
exogCoeff     | ,0.03772791
pCoeff        | -0.1416746 -0.2788988 -0.2048458 -0.5352439 -1.42802
qCoeff        | -0.9264254 -0.04674371
lagVals       | -0.4359039 -0.1012633 0.3720861 0.5743528 -0.4202239 -0.04983..
residualVals  | 0.4615449 0.2299498
residualCoeffs| 0.0003810419 -0.3362408 -0.7078495 -1.054529 -1.15638 -1.3141..
paramDict     | `p`q`trend!(5;2;1b)

.ml.kxi.ts.ARMA.fit

Fit an AutoRegressive Moving model

.ml.kxi.ts.ARMA.fit[endog]
.ml.kxi.ts.ARMA.fit[endog;config]

Where

  • endog is the numerical endogenous variable (variable determined by its relationship with others)
  • config is an optional dictionary argument containing modifications to default behavior, with keys

    key type default description
    exog table float[] ::
    p long 0 Is the number of lags to include in model generation
    q long 0 Is the number of residual errors to include in model generation
    trend boolean 1b Is a trend to be accounted for in generation of the model

returns a dictionary

modelInfo | all information needed to fit the original model 
            and returned during the fitting process 
predict   | a projection allowing for predictions on new input data 
q)endog:100?1f
q)exog:10+100?1f

// Fit a model using default configuration
q)show mdl1:.ml.kxi.ts.ARMA.fit[endog]
modelInfo| `coefficients`trendCoeff`exogCoeff`pCoeff`lagVals`qCoeff`residualV..
predict  | {[config;exog;len]
  model:config`modelInfo;
  exog:ts.i.predDataC..
q)mdl1`modelInfo
coefficients  | ,0.4955508
trendCoeff    | ,0.4955508
exogCoeff     | `float$()
pCoeff        | `float$()
lagVals       | `float$()
qCoeff        | ()
residualVals  | ()
residualCoeffs| ()
paramDict     | `p`q`trend!(0;0;1b)

// Fit a model modifying the default behavior
q)show mdl2:.ml.kxi.ts.ARMA.fit[endog;`exog`p`q!(exog;3;2)]
modelInfo| `coefficients`trendCoeff`exogCoeff`pCoeff`qCoeff`lagVals`residualV..
predict  | {[config;exog;len]
  model:config`modelInfo;
  exog:ts.i.predDataC..
q)mdl2`modelInfo
coefficients  | 1.406245 -0.07764113 -0.1519254 -0.1038931 0.0745155 0.212620..
trendCoeff    | 1.406245
exogCoeff     | ,-0.07764113
pCoeff        | -0.1519254 -0.1038931 0.0745155
qCoeff        | 0.2126203 -0.05684466
lagVals       | 0.08810016 0.6299055 0.7514869 0.8232365
residualVals  | 0.2605527 0.1726264
residualCoeffs| 0.05543747 -0.2116724 -0.08487247 0.1399949 -0.01148043
paramDict     | `p`q`trend!(3;2;1b)

.ml.kxi.ts.SARIMA.fit

Fit a Seasonal AutoRegressive Integrated Moving Average model

.ml.kxi.ts.SARIMA.fit[endog]
.ml.kxi.ts.SARIMA.fit[endog;config]

Where

  • endog is the numerical endogenous variable (variable determined by its relationship with others)
  • config is an optional dictionary argument containing modifications to default behavior, with keys

    key type default description
    exog table float[] ::
    p long 0 Is the number of lags to include in model generation
    q long 0 Is the number of residual errors to include in model generation
    d long 0 Is the number of differencing terms to include in model generation
    P long 0 Is the number of seasonal lags to include in model generation
    Q long 0 Is the number of seasonal residual errors to include in model generation
    D long 0 Is the number of seasonal differencing terms to include in model generation
    m long 0 Is the periodicity of the time series i.e. 4 for quarterly data, 12 for monthly data
    trend boolean 1b Is a trend to be accounted for in generation of the model

returns a dictionary

modelInfo | all information needed to fit the original model 
            and returned during the fitting process 
predict   | a projection allowing for predictions on new input data 
q)endog:100?1f
q)exog:([]100?1f;100?10f)

// Fit a model using default configuration
q)show mdl1:.ml.kxi.ts.SARIMA.fit[endog]
modelInfo| `coefficients`trendCoeff`exogCoeff`pCoeff`lagVals`qCoeff`residualV..
predict  | {[config;exog;len]
  model:config`modelInfo;
  exog:ts.i.predDataC..
q)mdl1`modelInfo
coefficients  | ,0.4955508
trendCoeff    | ,0.4955508
exogCoeff     | `float$()
pCoeff        | `float$()
lagVals       | `float$()
qCoeff        | ()
residualVals  | ()
residualCoeffs| ()
paramDict     | `p`q`trend!(0;0;1b)
originalData  | `float$()

// Fit a model modifying the default behavior
q)show mdl2:.ml.kxi.ts.SARIMA.fit[endog;`exog`p`d`q`P`D`Q`m!(exog;3;0;1;2;0;1;10)]
modelInfo| `coefficients`trendCoeff`exogCoeff`pCoeff`lagVals`qCoeff`residualV..
predict  | {[config;exog;len]
  model:config`modelInfo;
  exog:ts.i.predDataC..
q)mdl2`modelInfo
coefficients  | 0.5114756 -0.0810032 0.004972889 -0.02217438 0.1698094 -0.523..
trendCoeff    | 0.5114756
exogCoeff     | -0.0810032 0.004972889
pCoeff        | -0.02217438 0.1698094 -0.5233872
qCoeff        | ,0.5901153
PCoeff        | 0.2835886 0.1210252
QCoeff        | ,-0.2835886
lagVals       | 0.6458945 0.2286639 0.4354205 0.7844876 0.8665244 0.6767128 0..
residualVals  | 0.2935768 0.3357624 0.2876154 0.04145062 0.194916 -0.1708675 ..
residualCoeffs| 0.193646 0.005886717 0.03720493 0.1017816 0.3331299 0.2087178
paramDict     | `p`q`P`Q`m`trend`additionalP`additionalQ`n!(3;1;0 10;,0;10;1b..
originalData  | `float$()
seasonData    | `float$()