Stacking¶
Bayesian model stacking and ensemble prediction.
trade_study.stack_bayesian(compare_dict, *, method='stacking')
¶
Bayesian stacking via arviz.compare.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compare_dict
|
dict[str, Any]
|
Dictionary mapping model names to arviz DataTree or ELPDData objects (must contain log_likelihood group). |
required |
method
|
str
|
Weighting method. One of "stacking", "BB-pseudo-BMA", "pseudo-BMA". |
'stacking'
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary mapping model names to stacking weights. |
Source code in src/trade_study/stacking.py
trade_study.stack_scores(score_matrix, *, maximize=False)
¶
Optimize stacking weights from a score matrix.
For non-Bayesian models where log-likelihoods aren't available. Finds weights w on the simplex that optimize the weighted composite score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
score_matrix
|
NDArray[floating[Any]]
|
Array of shape (n_models, n_test_points) where each entry is the score of model i on test point j. |
required |
maximize
|
bool
|
If True, maximize the weighted score; if False, minimize. |
False
|
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Array of weights, shape (n_models,), summing to 1. |
Source code in src/trade_study/stacking.py
trade_study.ensemble_predict(predictions, weights)
¶
Weighted ensemble of model predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predictions
|
list[NDArray[floating[Any]]]
|
List of prediction arrays, one per model. Each should have the same shape. |
required |
weights
|
NDArray[floating[Any]]
|
Stacking weights, shape (n_models,). |
required |
Returns:
| Type | Description |
|---|---|
NDArray[floating[Any]]
|
Weighted average prediction array. |