CompositeSimilarity¶
yohou.interval.CompositeSimilarity
¶
Bases: BaseSimilarity, _BaseComposition
Combine multiple named similarity measures into a single weight vector.
Delegates fit, observe, rewind, and predict to each
sub-similarity and then combines their weight matrices using either
element-wise multiplication or weighted averaging. Sub-similarities are
named (name, similarity) tuples, so their parameters are tunable via
the similarities__<name>__<param> syntax (sklearn _BaseComposition).
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
similarities
|
list of (str, BaseSimilarity) tuples
|
At least two named sub-similarities to combine, e.g.
|
None
|
combination
|
(multiply, mean)
|
How to combine the individual weight matrices.
|
"multiply"
|
weights
|
list of float or None
|
Per-similarity exponents (multiply) or mixing coefficients
(mean), aligned with |
None
|
Attributes ¶
| Name | Type | Description |
|---|---|---|
similarities_ |
list of (str, BaseSimilarity) tuples
|
Fitted copies of the named sub-similarities (set after |
See Also ¶
DistanceSimilarity: Value-based distance similarity.SeasonalSimilarity: Seasonal-phase Fourier feature similarity.
Examples ¶
>>> from datetime import datetime, timedelta
>>> import polars as pl
>>> import numpy as np
>>> from yohou.interval.similarity import (
... CompositeSimilarity,
... DistanceSimilarity,
... SeasonalSimilarity,
... )
>>>
>>> dates = [datetime(2021, 1, 1) + timedelta(days=i) for i in range(28)]
>>> y = pl.DataFrame({"time": dates, "value": np.random.randn(28)})
>>> y_pred = pl.DataFrame({"time": dates, "value": np.random.randn(28)})
>>>
>>> comp = CompositeSimilarity(
... similarities=[
... ("dist", DistanceSimilarity(metric="euclidean")),
... ("seasonal", SeasonalSimilarity(seasonality=[7.0])),
... ],
... combination="multiply",
... )
>>> _ = comp.fit(y, y_pred)
>>> new_date = [datetime(2021, 1, 29)]
>>> y_pred_new = pl.DataFrame({"time": new_date, "value": [0.5]})
>>> weights = comp.predict(y_pred_new)
>>> weights.shape
(1, 28)
Source Code ¶
Source code in src/yohou/interval/similarity.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
Methods ¶
get_params(deep=True)
¶
Get parameters, including nested sub-similarity parameters.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
deep
|
bool
|
If True, include sub-similarity parameters as
|
True
|
Returns ¶
| Type | Description |
|---|---|
dict
|
Parameter names mapped to values. |
Source Code ¶
Source code in src/yohou/interval/similarity.py
set_params(**params)
¶
fit(y, y_pred, X_actual=None)
¶
Fit all sub-similarities on the calibration data.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y
|
DataFrame
|
Target time series. |
required |
y_pred
|
DataFrame
|
Point forecast time series. |
required |
X_actual
|
DataFrame or None
|
None
|
Returns ¶
| Type | Description |
|---|---|
self
|
|
Source Code ¶
Source code in src/yohou/interval/similarity.py
observe(y, y_pred, X_actual=None)
¶
Forward observation to all sub-similarities.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y
|
DataFrame
|
New target observations. |
required |
y_pred
|
DataFrame
|
New predictions. |
required |
X_actual
|
DataFrame or None
|
New exogenous features. |
None
|
Returns ¶
| Type | Description |
|---|---|
self
|
|
Source Code ¶
Source code in src/yohou/interval/similarity.py
rewind(y, y_pred, X_actual=None)
¶
Forward rewind to all sub-similarities.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y
|
DataFrame
|
Target observations to rewind. |
required |
y_pred
|
DataFrame
|
Predictions to rewind. |
required |
X_actual
|
DataFrame or None
|
Exogenous features to rewind. |
None
|
Returns ¶
| Type | Description |
|---|---|
self
|
|
Source Code ¶
Source code in src/yohou/interval/similarity.py
predict(y_pred, X_actual=None)
¶
Combine sub-similarity weights into a single weight matrix.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
y_pred
|
DataFrame
|
Predictions to compute similarities for. |
required |
X_actual
|
DataFrame or None
|
None
|
Returns ¶
| Type | Description |
|---|---|
ndarray
|
Combined weight matrix of shape
|