slisemap.tuning
Find optimal hyper-parameters for Slisemap and Slipmap.
hyperparameter_tune(method, X, y, X_test, y_test, lasso=(0.001, 10.0), ridge=(0.0001, 1.0), radius=(1.5, 4.0), *args, model=True, n_calls=15, verbose=False, random_state=42, predict_kws={}, optim_kws={}, gp_kws={}, **kwargs)
Tune the lasso
, ridge
, and radius
hyperparameters using Bayesian optimisation.
The search space is configured through the lasso
/ridge
/radius
arguments as follows:
- float: Skip the tuning of that hyperparameter.
- tuple: tune the parameters limited to the space of (lowerbound, upperbound)
.
This function selects a candidate set of hyperparameters using skopt.gp_minimize
.
For a given set of hyperparameters, a Slisemap/Slipmap model is trained on X
and y
.
Then the solution is evaluated using X_test
and y_test
.
This procedure is repeated for n_calls
iterations before the best result is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method |
Union[Type[Slisemap], Type[Slipmap]]
|
Method to tune, either |
required |
X |
ToTensor
|
Data matrix. |
required |
y |
ToTensor
|
target matrix. |
required |
X_test |
ToTensor
|
New data for evaluation. |
required |
y_test |
ToTensor
|
New data for evaluation. |
required |
lasso |
Union[float, Tuple[float, float]]
|
Limits for the |
(0.001, 10.0)
|
ridge |
Union[float, Tuple[float, float]]
|
Limits for the |
(0.0001, 1.0)
|
radius |
Union[float, Tuple[float, float]]
|
Limits for the |
(1.5, 4.0)
|
*args |
Any
|
Arguments forwarded to |
()
|
Other Parameters:
Name | Type | Description |
---|---|---|
model |
bool
|
Return a trained model instead of a dictionary with tuned parameters. Defaults to True. |
n_calls |
int
|
Number of parameter evaluations. Defaults to 15. |
verbose |
bool
|
Print status messages. Defaults to False. |
random_state |
int
|
Random seed. Defaults to 42. |
predict_kws |
Dict[str, object]
|
Keyword arguments forwarded to |
optim_kws |
Dict[str, object]
|
Keyword arguments forwarded to |
gp_kws |
Dict[str, object]
|
Keyword arguments forwarded to |
**kwargs |
Any
|
Keyword arguments forwarded to |
Raises:
Type | Description |
---|---|
ImportError
|
If |
Returns:
Type | Description |
---|---|
Union[Slisemap, Slipmap, Dict[str, float]]
|
Dictionary with hyperparameter values or a Slisemap/Slipmap model trained on those (see the |
Source code in slisemap/tuning.py
22 23 24 25 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 |
|
optimise_with_test(sm, X_test, y_test, lasso_grid=3.0, ridge_grid=3.0, radius_grid=1.1, search_size=6, test=accuracy, patience=2, max_escapes=100, verbose=0, escape_kws={}, *, max_iterations=None, **kwargs)
Optimise a Slisemap or Slipmap object using test data to tune the regularisation.
How this works
- The procedure is very similar to Slisemap.optimise, which alternates between LBFGS optimisation and an "escape" heuristic until convergence.
- The hyperoptimisation tuning adds an additional step after each call to LBFGS where a small local search is performed to tune the hyperparameters.
- The convergence criteria is also changed to use the test data (see the
test
parameter). - This should be faster than the usual "outer-loop" hyperperameter optimisation, but the local search dynamics might be less exhaustive.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Union[Slisemap, Slipmap]
|
Slisemap or Slipmap object. |
required |
X_test |
Union[ndarray, Tensor]
|
Data matrix for the test set. |
required |
y_test |
Union[ndarray, Tensor]
|
Target matrix/vector for the test set. |
required |
lasso_grid |
float
|
The extent of the local search for the lasso parameter |
3.0
|
ridge_grid |
float
|
The extent of the local search for the ridge parameter |
3.0
|
radius_grid |
float
|
The extent of the local search for the radius parameter |
1.1
|
search_size |
int
|
The number of evaluations in the local random search. Defaults to 6. |
6
|
test |
Callable[[Slisemap, Tensor, Tensor], float]
|
Test to measure the performance of different hyperparameter values. Defaults to accuracy. |
accuracy
|
patience |
int
|
Number of optimisation rounds without improvement before stopping. Defaults to 2. |
2
|
max_escapes |
int
|
Maximum numbers optimisation rounds. Defaults to 100. |
100
|
verbose |
Literal[0, 1, 2, 3]
|
Print status messages. Defaults to 0. |
0
|
escape_kws |
Dict[str, Any]
|
Keyword arguments forwarded to sm.escape. Defaults to {}. |
{}
|
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs |
Any
|
Optional keyword arguments to sm.lbfgs. |
Returns:
Type | Description |
---|---|
Union[Slisemap, Slipmap]
|
Optimised Slisemap or Slipmap object. This is not the same object as the input! |
Deprecated
1.6: max_iterations
renamed to max_escapes
Source code in slisemap/tuning.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
optimise_with_cv(sm, k=5, lasso_grid=3.0, ridge_grid=3.0, radius_grid=1.1, search_size=6, lerp=0.3, test=accuracy, patience=2, max_escapes=100, verbose=0, escape_kws={}, *, max_iterations=None, **kwargs)
Optimise a Slisemap or Slipmap object using cross validation to tune the regularisation.
How this works
- The data is split into k folds for cross validation.
- Then a procedure like optimise_with_test is used.
- After every hyperparameter tuning the regularisation coefficients are smoothed across the folds (see the
lerp
parameter). - Finally, when the cross validation has converged the solution is transferred to the complete data for one final optimisation.
- Note that this is significantly slower than just training on Slisemap solution.
- However, this should be faster than the usual "outer-loop" hyperperameter optimisation (but the local search dynamics might be less exhaustive).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Union[Slisemap, Slipmap]
|
Slisemap or Slipmap object. |
required |
k |
int
|
Number of folds for the cross validation. Defaults to 5. |
5
|
lasso_grid |
float
|
The extent of the local search for the lasso parameter |
3.0
|
ridge_grid |
float
|
The extent of the local search for the ridge parameter |
3.0
|
radius_grid |
float
|
The extent of the local search for the radius parameter |
1.1
|
search_size |
int
|
The number of evaluations in the local random search. Defaults to 6. |
6
|
lerp |
float
|
Smooth regularisation coefficients across folds (linearly interpolating towards the mean coefficients). Defaults to 0.3. |
0.3
|
test |
Callable[[Slisemap, Tensor, Tensor], float]
|
Test to measure the performance of different hyperparameter values. Defaults to accuracy. |
accuracy
|
patience |
int
|
Number of optimisation rounds without improvement before stopping. Defaults to 1. |
2
|
max_escapes |
int
|
Maximum numbers optimisation rounds. Defaults to 100. |
100
|
verbose |
Literal[0, 1, 2, 3]
|
Print status messages. Defaults to 0. |
0
|
escape_kws |
Dict[str, Any]
|
Keyword arguments forwarded to sm.escape. Defaults to {}. |
{}
|
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs |
Any
|
Optional keyword arguments to sm.lbfgs. |
Returns:
Type | Description |
---|---|
Union[Slisemap, Slipmap]
|
Optimised Slisemap or Slipmap object. |
Deprecated
1.6: max_iterations
renamed to max_escapes
Source code in slisemap/tuning.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
|
optimise(sm, X_test=None, y_test=None, **kwargs)
Optimise a Slisemap or Slipmap object with hyperparameter tuning.
This can either be done using a test set or cross validation.
The choice of method is based on whether X_test
and y_test
is given.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sm |
Union[Slisemap, Slipmap]
|
Slisemap or Slipmap object. |
required |
X_test |
Union[None, ndarray, Tensor]
|
Data matrix for the test set. Defaults to None. |
None
|
y_test |
Union[None, ndarray, Tensor]
|
Target matrix/vector for the test set. Defaults to None. |
None
|
Other Parameters:
Name | Type | Description |
---|---|---|
**kwargs |
Any
|
Optional keyword arguments to slisemap.tuning.optimise_with_test or slisemap.tuning.optimise_with_cv. |
Returns:
Type | Description |
---|---|
Union[Slisemap, Slipmap]
|
Optimised Slisemap or Slipmap object. This is not the same object as the input! |
Deprecated
1.6: Use the uncerlying function directly instead
Source code in slisemap/tuning.py
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
|