Linear weights
timecave.validation_methods.weights.linear_weights(n_splits, gap=0, compensation=0, params={'slope': 2})
Compute linear weights.
This function computes a linear weight vector. It may be passed to the Growing Window, Rolling Window, and Block CV classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_splits |
int
|
Number of splits the validation method will use. |
required |
gap |
int
|
Number of folds separating the validation set from the training set. Used by prequential methods. |
0
|
compensation |
int
|
A compensation factor that allows the function to generate the correct amount of weights. 0 for CV methods, +1 for prequential methods. Additionally, if a gap is specified, it must be added to this compensation factor as well. |
0
|
params |
dict
|
Parameters from which to generate the weights. Only |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Weights. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Examples:
>>> from timecave.validation_methods.weights import linear_weights
>>> linear_weights(5);
array([0.06666667, 0.13333333, 0.2 , 0.26666667, 0.33333333])
If a gap is specified, there will be fewer iterations. Therefore, fewer weights should be generated:
For a given number of folds, CV methods will run for an additional iteration compared to prequential methods. Therefore, a compensation factor of 1 must be specified if one intends to use weighted prequential methods: