hyperriver
HyperRiver
¶
Hyperparameter Tuning for River.
Source code in spotriver/fun/hyperriver.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
__init__(weights=np.array([1, 0, 0]), seed=126, log_level=50)
¶
Initialize the class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
weights |
array
|
An array of weights for error, r_time, and memory. Defaults to [1, 0, 0], which considers only the error. |
array([1, 0, 0])
|
seed |
int
|
seed. Defaults to 126. |
126
|
log_level |
int
|
The level of logging to use. 0 = no logging, 50 = print only important information. Defaults to 50. |
50
|
Returns:
Type | Description |
---|---|
NoneType
|
None |
Examples:
>>> from spotriver.fun.hyperriver import HyperRiver
>>> import pandas as pd
>>> hr = HyperRiver(weights=[1, 2, 3])
>>> df_eval = pd.DataFrame( [[1, 2, 3], [3, 4, 5]], columns=['Metric', 'CompTime (s)', 'Memory (MB)'])
>>> hr.compute_y(df_eval)
20.0
Source code in spotriver/fun/hyperriver.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
check_X_shape(X)
¶
Check the shape of X.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
ndarray
|
The input data. |
required |
Returns:
Type | Description |
---|---|
NoneType
|
None |
Examples:
>>> X = np.array([[1, 2, 3], [4, 5, 6]])
>>> check_X_shape(X)
>>> X = np.array([1, 2, 3])
>>> check_X_shape(X)
Traceback (most recent call last):
...
Exception
Source code in spotriver/fun/hyperriver.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
compute_y(df_eval)
¶
Compute the objective function value as a weighted sum of the errors, running time, and memory usage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_eval |
DataFrame
|
DataFrame with the evaluation results. Columns must have the following names: - “Metric”: The evaluation metric. - “CompTime (s)”: The running time. - “Memory (MB)”: The memory usage. |
required |
Returns:
Type | Description |
---|---|
float
|
objective function value. Weighted mean of the errors, running time, and memory usage. |
Examples:
>>> from spotriver.fun.hyperriver import HyperRiver
hr = HyperRiver()
# set the weights
hr.fun_control["weights"] = [1, 1, 1]
df_eval = pd.DataFrame( [[1, 2, 3], [3, 4, 5]], columns=['Metric', 'CompTime (s)', 'Memory (MB)'])
hr.compute_y(df_eval)
Source code in spotriver/fun/hyperriver.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
evaluate_model(model, fun_control)
¶
Evaluates a model using the eval_oml_horizon function from spotriver.evaluation.eval_bml.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
object
|
The model to be evaluated. |
required |
fun_control |
dict
|
A dictionary containing the following keys: - train (pd.DataFrame): The training data. - test (pd.DataFrame): The testing data. - target_column (str): The name of the target column. - horizon (int): The horizon value. - oml_grace_period (int): The oml_grace_period value. - metric_sklearn (str): The metric to be used for evaluation. |
required |
Returns:
Type | Description |
---|---|
Tuple[DataFrame, DataFrame]
|
A tuple containing two dataframes: - df_eval: The evaluation dataframe. - df_preds: The predictions dataframe. |
Examples:
>>> model = SomeModel()
>>> fun_control = {
... "train": train_data,
... "test": test_data,
... "target_column": "target",
... "horizon": 5,
... "oml_grace_period": 10,
... "metric_sklearn": "accuracy"
... }
>>> df_eval, df_preds = evaluate_model(model, fun_control)
Source code in spotriver/fun/hyperriver.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
fun_oml_horizon(X, fun_control=None)
¶
The objective function for hyperparameter tuning. Prepares the data and calls the evaluate_model function. This function takes in input data and a dictionary of control parameters to compute the objective function values for hyperparameter tuning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X |
ndarray
|
The input data. |
required |
fun_control |
dict
|
A dictionary containing the following keys: - train (pd.DataFrame): The training data. - test (pd.DataFrame): The testing data. - target_column (str): The name of the target column. - horizon (int): The horizon value. - oml_grace_period (int): The oml_grace_period value. - metric_sklearn (str): The metric to be used for evaluation. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
The objective function values. |
Examples:
>>> fun_oml_horizon(X,
fun_control={'train': train_data,
'test': test_data,
'target_column': 'y',
'horizon': 5,
'oml_grace_period': 10,
'metric_sklearn': 'accuracy'})
array([0.8, 0.85, 0.9])
Source code in spotriver/fun/hyperriver.py
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
get_river_df_eval_preds(model)
¶
Get the evaluation and prediction dataframes for a river model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
object
|
The model to be evaluated. |
required |
Returns:
Type | Description |
---|---|
Tuple[DataFrame, DataFrame]
|
A tuple containing two dataframes: - df_eval: The evaluation dataframe. - df_preds: The predictions dataframe. |
Examples:
>>> model = SomeModel()
>>> df_eval, df_preds = get_river_df_eval_preds(model)
Source code in spotriver/fun/hyperriver.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|