|
8 | 8 | F1, |
9 | 9 | MAPE, |
10 | 10 | MSE, |
| 11 | + SMAPE, |
11 | 12 | AccuracyBinary, |
12 | 13 | AccuracyMulticlass, |
13 | 14 | BalancedAccuracyBinary, |
@@ -711,6 +712,44 @@ def test_mape_time_series_model(): |
711 | 712 | ) == pytest.approx(8 / 4 * 100) |
712 | 713 |
|
713 | 714 |
|
| 715 | +def test_smape_time_series_model(): |
| 716 | + obj = SMAPE() |
| 717 | + |
| 718 | + s1_actual = np.array([0, 0, 1, 1, 1, 1, 2, 0, 2]) |
| 719 | + s1_predicted = np.array([0, 1, 0, 1, 1, 2, 1, 2, 0]) |
| 720 | + |
| 721 | + s2_actual = np.array([-1, -2, 1, 3]) |
| 722 | + s2_predicted = np.array([1, 2, -1, -3]) |
| 723 | + |
| 724 | + s3_actual = np.array([1, 2, 4, 2, 1, 2]) |
| 725 | + s3_predicted = np.array([0, 2, 2, 0, 3, 2]) |
| 726 | + |
| 727 | + s4_actual = np.array([0, 2, 0, 2, 1, 2]) |
| 728 | + s4_predicted = np.array([1, 2, 2, 1, 3, 2]) |
| 729 | + |
| 730 | + with pytest.raises( |
| 731 | + ValueError, |
| 732 | + match="Symmetric Mean Absolute Percentage Error cannot be used when " |
| 733 | + "true and predicted targets both contain the value 0.", |
| 734 | + ): |
| 735 | + obj.score(s1_actual, s1_predicted) |
| 736 | + assert obj.score(s2_actual, s2_predicted) == pytest.approx(8 / 4 * 100) |
| 737 | + assert obj.score(s3_actual, s3_predicted) == pytest.approx((17 / 6) / 3 * 100) |
| 738 | + assert obj.score(s4_actual, s4_predicted) == pytest.approx((17 / 6) / 3 * 100) |
| 739 | + assert obj.score( |
| 740 | + pd.Series(s3_actual, index=range(-12, -6)), |
| 741 | + s3_predicted, |
| 742 | + ) == pytest.approx((17 / 6) / 3 * 100) |
| 743 | + assert obj.score( |
| 744 | + pd.Series(s2_actual, index=range(10, 14)), |
| 745 | + pd.Series(s2_predicted, index=range(20, 24)), |
| 746 | + ) == pytest.approx(8 / 4 * 100) |
| 747 | + assert obj.score( |
| 748 | + pd.Series(s4_actual, index=range(-12, -6)), |
| 749 | + s4_predicted, |
| 750 | + ) == pytest.approx((17 / 6) / 3 * 100) |
| 751 | + |
| 752 | + |
714 | 753 | @pytest.mark.parametrize("objective_class", _all_objectives_dict().values()) |
715 | 754 | def test_calculate_percent_difference(objective_class): |
716 | 755 | score = 5 |
|
0 commit comments