|
31 | 31 | import numpy as np |
32 | 32 | import pandas as pd |
33 | 33 |
|
34 | | -example_dict = dict() |
35 | | -example_dict_lossy = dict() |
36 | | -example_dict_metadata = dict() |
| 34 | +from skpro.datatypes._base import BaseExample |
37 | 35 |
|
38 | 36 | ### |
39 | 37 | # example 0: univariate |
40 | 38 |
|
41 | | -pred_q = pd.DataFrame({0.2: [1, 2, 3], 0.6: [2, 3, 4]}) |
42 | | -pred_q.columns = pd.MultiIndex.from_product([["foo"], [0.2, 0.6]]) |
43 | 39 |
|
44 | | -# we need to use this due to numerical inaccuracies from the binary based representation |
45 | | -pseudo_0_2 = 2 * np.abs(0.6 - 0.5) |
| 40 | +class _ProbaUniv(BaseExample): |
| 41 | + _tags = { |
| 42 | + "scitype": "Proba", |
| 43 | + "index": 0, |
| 44 | + "metadata": { |
| 45 | + "is_univariate": True, |
| 46 | + "is_empty": False, |
| 47 | + "has_nans": False, |
| 48 | + }, |
| 49 | + } |
46 | 50 |
|
47 | | -example_dict[("pred_quantiles", "Proba", 0)] = pred_q |
48 | | -example_dict_lossy[("pred_quantiles", "Proba", 0)] = False |
49 | 51 |
|
50 | | -pred_int = pd.DataFrame({0.2: [1, 2, 3], 0.6: [2, 3, 4]}) |
51 | | -pred_int.columns = pd.MultiIndex.from_tuples( |
52 | | - [("foo", 0.6, "lower"), ("foo", pseudo_0_2, "upper")] |
53 | | -) |
| 52 | +class _ProbaUnivPredQ(_ProbaUniv): |
| 53 | + _tags = { |
| 54 | + "mtype": "pred_quantiles", |
| 55 | + "python_dependencies": None, |
| 56 | + "lossy": False, |
| 57 | + } |
54 | 58 |
|
55 | | -example_dict[("pred_interval", "Proba", 0)] = pred_int |
56 | | -example_dict_lossy[("pred_interval", "Proba", 0)] = False |
| 59 | + def build(self): |
| 60 | + pred_q = pd.DataFrame({0.2: [1, 2, 3], 0.6: [2, 3, 4]}) |
| 61 | + pred_q.columns = pd.MultiIndex.from_product([["foo"], [0.2, 0.6]]) |
57 | 62 |
|
| 63 | + return pred_q |
| 64 | + |
| 65 | + |
| 66 | +class _ProbaUnivPredInt(_ProbaUniv): |
| 67 | + _tags = { |
| 68 | + "mtype": "pred_interval", |
| 69 | + "python_dependencies": None, |
| 70 | + "lossy": False, |
| 71 | + } |
| 72 | + |
| 73 | + def build(self): |
| 74 | + # we need to use this due to numerical inaccuracies |
| 75 | + # from the binary based representation |
| 76 | + pseudo_0_2 = 2 * np.abs(0.6 - 0.5) |
| 77 | + |
| 78 | + pred_int = pd.DataFrame({0.2: [1, 2, 3], 0.6: [2, 3, 4]}) |
| 79 | + pred_int.columns = pd.MultiIndex.from_tuples( |
| 80 | + [("foo", 0.6, "lower"), ("foo", pseudo_0_2, "upper")] |
| 81 | + ) |
| 82 | + |
| 83 | + return pred_int |
58 | 84 |
|
59 | | -example_dict_metadata[("Proba", 0)] = { |
60 | | - "is_univariate": True, |
61 | | - "is_empty": False, |
62 | | - "has_nans": False, |
63 | | -} |
64 | 85 |
|
65 | 86 | ### |
66 | 87 | # example 1: multi |
67 | 88 |
|
68 | | -pred_q = pd.DataFrame({0.2: [1, 2, 3], 0.6: [2, 3, 4], 42: [5, 3, -1], 46: [5, 3, -1]}) |
69 | | -pred_q.columns = pd.MultiIndex.from_product([["foo", "bar"], [0.2, 0.6]]) |
70 | | - |
71 | | -example_dict[("pred_quantiles", "Proba", 1)] = pred_q |
72 | | -example_dict_lossy[("pred_quantiles", "Proba", 1)] = False |
73 | | - |
74 | | -pred_int = pd.DataFrame( |
75 | | - {0.2: [1, 2, 3], 0.6: [2, 3, 4], 42: [5, 3, -1], 46: [5, 3, -1]} |
76 | | -) |
77 | | -pred_int.columns = pd.MultiIndex.from_tuples( |
78 | | - [ |
79 | | - ("foo", 0.6, "lower"), |
80 | | - ("foo", pseudo_0_2, "upper"), |
81 | | - ("bar", 0.6, "lower"), |
82 | | - ("bar", pseudo_0_2, "upper"), |
83 | | - ] |
84 | | -) |
85 | | - |
86 | | -example_dict[("pred_interval", "Proba", 1)] = pred_int |
87 | | -example_dict_lossy[("pred_interval", "Proba", 1)] = False |
88 | | - |
89 | | - |
90 | | -example_dict_metadata[("Proba", 1)] = { |
91 | | - "is_univariate": False, |
92 | | - "is_empty": False, |
93 | | - "has_nans": False, |
94 | | -} |
| 89 | + |
| 90 | +class _ProbaMulti(BaseExample): |
| 91 | + _tags = { |
| 92 | + "scitype": "Proba", |
| 93 | + "index": 1, |
| 94 | + "metadata": { |
| 95 | + "is_univariate": False, |
| 96 | + "is_empty": False, |
| 97 | + "has_nans": False, |
| 98 | + }, |
| 99 | + } |
| 100 | + |
| 101 | + |
| 102 | +class _ProbaMultiPredQ(_ProbaMulti): |
| 103 | + _tags = { |
| 104 | + "mtype": "pred_quantiles", |
| 105 | + "python_dependencies": None, |
| 106 | + "lossy": False, |
| 107 | + } |
| 108 | + |
| 109 | + def build(self): |
| 110 | + pred_q = pd.DataFrame( |
| 111 | + {0.2: [1, 2, 3], 0.6: [2, 3, 4], 42: [5, 3, -1], 46: [5, 3, -1]} |
| 112 | + ) |
| 113 | + pred_q.columns = pd.MultiIndex.from_product([["foo", "bar"], [0.2, 0.6]]) |
| 114 | + |
| 115 | + return pred_q |
| 116 | + |
| 117 | + |
| 118 | +class _ProbaMultiPredInt(_ProbaMulti): |
| 119 | + _tags = { |
| 120 | + "mtype": "pred_interval", |
| 121 | + "python_dependencies": None, |
| 122 | + "lossy": False, |
| 123 | + } |
| 124 | + |
| 125 | + def build(self): |
| 126 | + # we need to use this due to numerical inaccuracies |
| 127 | + # from the binary based representation |
| 128 | + pseudo_0_2 = 2 * np.abs(0.6 - 0.5) |
| 129 | + |
| 130 | + pred_int = pd.DataFrame( |
| 131 | + {0.2: [1, 2, 3], 0.6: [2, 3, 4], 42: [5, 3, -1], 46: [5, 3, -1]} |
| 132 | + ) |
| 133 | + pred_int.columns = pd.MultiIndex.from_tuples( |
| 134 | + [ |
| 135 | + ("foo", 0.6, "lower"), |
| 136 | + ("foo", pseudo_0_2, "upper"), |
| 137 | + ("bar", 0.6, "lower"), |
| 138 | + ("bar", pseudo_0_2, "upper"), |
| 139 | + ] |
| 140 | + ) |
| 141 | + |
| 142 | + return pred_int |
0 commit comments