API Reference
Estimators
PretrainedLasso
ptlasso.PretrainedLasso
Bases: RegressorMixin, BasePretrainedLasso
Pretrained Lasso estimator.
Two-step training:
1. Fit an overall Lasso on all samples (lambda selected by internal CV).
2. For each group, fit a group-specific Lasso with offset
(1 - alpha) * eta_overall, where eta_overall is the overall
linear predictor (before the link function). Features not selected
by the overall model receive a stronger penalty of 1 / alpha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float in [0, 1]
|
Pretraining strength. |
0.5
|
family
|
(gaussian, binomial, multinomial)
|
Response distribution. |
"gaussian"
|
overall_lambda
|
('lambda.1se', 'lambda.min')
|
Lambda selection rule for the stage-1 overall model.
|
"lambda.1se"
|
fit_intercept
|
bool
|
Whether to fit an intercept in every sub-model. |
True
|
lmda_path_size
|
int
|
Number of lambdas in the regularisation path. |
100
|
min_ratio
|
float
|
Ratio of the smallest to largest lambda on the path. |
0.0001
|
verbose
|
bool
|
Whether to display fitting progress and a summary after training. Adelie's internal output is always suppressed regardless of this setting. |
True
|
standardize
|
bool
|
Whether to standardize features before fitting each sub-model.
Each model standardizes using only its own training data subset,
matching R's |
True
|
n_folds
|
int
|
Number of folds used for (a) adelie's internal lambda-selection CV and (b) the OOF predictions within each group model. Capped by the minimum per-group class size for classification families. |
10
|
n_threads
|
int
|
Number of threads passed to adelie's solver. Set to a higher value
to parallelise the coordinate descent within each model fit.
|
-1
|
Attributes:
| Name | Type | Description |
|---|---|---|
overall_model_ |
adelie state
|
Fitted overall Lasso (stage 1). |
overall_coef_ |
ndarray of shape (n_features,) or (n_features, K)
|
Coefficients from the overall model at the selected lambda.
Shape is |
overall_intercept_ |
float
|
Intercept from the overall model. Not set for multinomial. |
overall_lmda_idx_ |
int
|
Index into |
pretrain_models_ |
dict {group -> adelie state}
|
Per-group fitted Lasso models (stage 2, with pretraining offset). |
pretrain_lmda_idx_ |
dict {group -> int}
|
CV-selected lambda index for each pretrain group model ( |
individual_models_ |
dict {group -> adelie state}
|
Per-group fitted Lasso models without any pretraining offset. |
individual_lmda_idx_ |
dict {group -> int}
|
CV-selected lambda index for each individual group model ( |
groups_ |
ndarray
|
Unique group labels seen during fit. |
n_features_in_ |
int
|
Number of features seen during fit. |
feature_names_in_ |
ndarray of str or None
|
Feature names, if provided. |
n_classes_ |
int or None
|
Number of classes for multinomial; |
References
Craig, E., Pilanci, M., Le Menestrel, T., Narasimhan, B., Rivas, M. A., Gullaksen, S. E., & Tibshirani, R. (2025). Pretraining and the lasso. Journal of the Royal Statistical Society Series B, qkaf050.
Source code in src/ptlasso/_estimator.py
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 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 366 367 368 369 370 371 372 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 509 510 511 512 513 514 515 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 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 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 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 | |
fit
Fit the pretrained Lasso.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array-like of shape (n_samples, n_features)
|
Training data. |
required |
y
|
array-like of shape (n_samples,)
|
Target values. For |
required |
groups
|
array-like of shape (n_samples,)
|
Group membership for each sample. Must contain at least two distinct values. |
required |
group_labels
|
dict or None
|
Optional mapping from group values to display names used in
|
None
|
feature_names
|
array-like of str or None
|
Feature names. Inferred from |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
PretrainedLasso
|
Fitted estimator. |
Source code in src/ptlasso/_estimator.py
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 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 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 | |
predict
Predict target values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array-like of shape (n_samples, n_features)
|
|
required |
groups
|
array-like of shape (n_samples,)
|
|
required |
model
|
(pretrain, individual, overall)
|
|
"pretrain"
|
type
|
(response, link, 'class')
|
Scale of the returned predictions.
|
"response"
|
lmda_idx
|
int or None
|
Lambda index for group models. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y_pred |
ndarray
|
Shape |
Source code in src/ptlasso/_estimator.py
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 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 | |
score
Return a scalar performance metric using the pretrained model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array-like of shape (n_samples, n_features)
|
|
required |
y
|
array-like of shape (n_samples,)
|
|
required |
groups
|
array-like of shape (n_samples,)
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
score |
float
|
R² for gaussian; classification accuracy for binomial/multinomial. |
Source code in src/ptlasso/_estimator.py
evaluate
Predict and score with all three sub-models.
Convenience method matching R's predict(fit, xtest, ytest=ytest).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array-like of shape (n_samples, n_features)
|
|
required |
y
|
array-like of shape (n_samples,)
|
|
required |
groups
|
array-like of shape (n_samples,)
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
dict
|
Keys are
|
Source code in src/ptlasso/_estimator.py
get_coef
Return fitted coefficients as a nested dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
(all, overall, pretrain, individual)
|
Which sub-model(s) to return. |
"all"
|
lmda_idx
|
int or None
|
Lambda index for group models. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
coefs |
dict
|
When |
Source code in src/ptlasso/_estimator.py
PretrainedLassoCV
ptlasso.PretrainedLassoCV
Bases: RegressorMixin, BasePretrainedLasso
Pretrained Lasso with cross-validation over alpha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alphas
|
array - like or None
|
Candidate pretraining strengths. Defaults to [0, 0.25, 0.5, 0.75, 1.0].
|
None
|
n_folds
|
int
|
Number of folds used for (a) adelie's internal lambda-selection CV and (b) the OOF predictions that drive alpha selection. Capped by the minimum per-group class size for classification families. |
10
|
alphahat_choice
|
(overall, mean)
|
|
"overall"
|
family
|
(gaussian, binomial, multinomial)
|
Response distribution. |
"gaussian"
|
overall_lambda
|
('lambda.1se', 'lambda.min')
|
Lambda selection rule for the stage-1 overall model. |
"lambda.1se"
|
fit_intercept
|
bool
|
Whether to fit an intercept in every sub-model. |
True
|
lmda_path_size
|
int
|
Number of lambdas in the regularisation path. |
100
|
min_ratio
|
float
|
Ratio of the smallest to largest lambda on the path. |
0.0001
|
verbose
|
bool
|
Whether to display fitting progress and a summary after training. Adelie's internal output is always suppressed regardless of this setting. |
True
|
standardize
|
bool
|
Whether to standardize features before fitting each sub-model.
Each model standardizes using only its own training data subset,
matching R's |
True
|
foldid
|
array-like of int or None
|
Fold assignments, one integer per sample. When provided, overrides
the internal |
None
|
n_threads
|
int
|
Number of threads passed to adelie's solver. Set to a higher value
to parallelise the coordinate descent within each model fit.
|
-1
|
type_measure
|
(deviance, mse, mae, auc, 'class')
|
CV criterion used for both internal lambda selection and alpha selection,
matching R's single
|
"deviance"
|
Attributes:
| Name | Type | Description |
|---|---|---|
alpha_ |
float
|
Best alpha selected by CV (based on |
varying_alphahat_ |
dict {group -> float}
|
Per-group best alpha. |
cv_results_ |
dict {alpha -> float}
|
Global mean CV loss per alpha. |
cv_results_se_ |
dict {alpha -> float}
|
Standard error of global CV loss. |
cv_results_per_group_ |
dict {alpha -> {group -> float}}
|
Mean CV loss per alpha per group. |
cv_results_mean_ |
dict {alpha -> float}
|
Unweighted mean of per-group CV losses. |
cv_results_wtd_mean_ |
dict {alpha -> float}
|
Group-size-weighted mean of per-group CV losses. |
cv_results_individual_ |
float
|
Global CV loss for the individual (no-pretraining) model. |
cv_results_overall_ |
float
|
Global CV loss for the overall model. |
best_estimator_ |
PretrainedLasso
|
Full-data refit at the globally selected |
all_estimators_ |
dict {alpha -> PretrainedLasso}
|
Full-data refits for each unique alpha needed by |
References
Craig, E., Pilanci, M., Le Menestrel, T., Narasimhan, B., Rivas, M. A., Gullaksen, S. E., & Tibshirani, R. (2025). Pretraining and the lasso. Journal of the Royal Statistical Society Series B, qkaf050.
Source code in src/ptlasso/_cv.py
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 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 366 367 368 369 370 371 372 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 509 510 511 512 513 514 515 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 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 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 | |
fit
Fit PretrainedLassoCV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array-like of shape (n_samples, n_features)
|
Training data. |
required |
y
|
array-like of shape (n_samples,)
|
Target values. For |
required |
groups
|
array-like of shape (n_samples,)
|
Group membership for each sample. Must contain at least two distinct values. |
required |
group_labels
|
dict or None
|
Optional mapping from group values to display names used in
|
None
|
feature_names
|
array-like of str or None
|
Feature names. Inferred from |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
PretrainedLassoCV
|
Fitted estimator. |
Source code in src/ptlasso/_cv.py
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 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 366 367 368 369 370 371 372 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 | |
predict
Predict target values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array-like of shape (n_samples, n_features)
|
|
required |
groups
|
array-like of shape (n_samples,)
|
|
required |
model
|
(pretrain, individual, overall)
|
|
"pretrain"
|
type
|
(response, link, 'class')
|
Scale of the returned predictions. See :meth: |
"response"
|
alphatype
|
(best, varying)
|
|
"best"
|
lmda_idx
|
int or None
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
y_pred |
ndarray of shape (n_samples,) or (n_samples, K)
|
Shape is |
Source code in src/ptlasso/_cv.py
evaluate
Predict and score with all three sub-models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array-like of shape (n_samples, n_features)
|
|
required |
y
|
array-like of shape (n_samples,)
|
|
required |
groups
|
array-like of shape (n_samples,)
|
|
required |
alphatype
|
(best, varying)
|
|
"best"
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
dict
|
Keys are
|
Source code in src/ptlasso/_cv.py
score
Return a scalar performance metric using the best estimator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array-like of shape (n_samples, n_features)
|
|
required |
y
|
array-like of shape (n_samples,)
|
|
required |
groups
|
array-like of shape (n_samples,)
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
score |
float
|
R² for gaussian; classification accuracy for binomial/multinomial. |
Source code in src/ptlasso/_cv.py
get_coef
Return fitted coefficients from the best estimator.
Delegates to :meth:PretrainedLasso.get_coef.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
(all, overall, pretrain, individual)
|
|
"all"
|
**kwargs
|
Forwarded to :meth: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
coefs |
dict
|
See :meth: |
Source code in src/ptlasso/_cv.py
Support utilities
ptlasso.get_overall_support
Nonzero features from the overall model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
PretrainedLasso or PretrainedLassoCV
|
|
required |
lmda_idx
|
int or None
|
Index into the overall model's lambda path.
Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
support |
ndarray of int or str
|
|
Source code in src/ptlasso/_support.py
ptlasso.get_pretrain_support
Nonzero features from the per-group pretrained models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
PretrainedLasso or PretrainedLassoCV
|
|
required |
lmda_idx
|
int or None
|
Lambda index for the pretrained group models. When |
None
|
groups
|
array - like or None
|
Subset of group labels to consider. Default is all groups. |
None
|
include_overall
|
bool
|
Union the per-group support with the overall model support.
Ignored when |
True
|
common_only
|
bool
|
If True, return only features selected by more than half the groups. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
support |
ndarray of int or str
|
|
Source code in src/ptlasso/_support.py
ptlasso.get_pretrain_support_split
Split pretrain support into stage-1 ("common") and stage-2 ("individual") parts.
Mirrors the R package's suppre.common / suppre.individual convention:
- common : features selected by the overall model (stage 1).
- individual : features selected by the per-group models (stage 2) that are not in the common support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
PretrainedLasso or PretrainedLassoCV
|
|
required |
lmda_idx
|
int or None
|
Lambda index for the group models. When |
None
|
groups
|
array - like or None
|
Subset of group labels. Default is all groups. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
common |
ndarray of int or str
|
|
individual |
ndarray of int or str
|
|
Source code in src/ptlasso/_support.py
ptlasso.get_individual_support
Nonzero features from the per-group individual (no-pretraining) models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
PretrainedLasso or PretrainedLassoCV
|
|
required |
lmda_idx
|
int or None
|
Lambda index for the individual group models. When |
None
|
groups
|
array - like or None
|
Subset of group labels to consider. Default is all groups. |
None
|
common_only
|
bool
|
If True, return only features selected by more than half the groups. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
support |
ndarray of int or str
|
|
Source code in src/ptlasso/_support.py
Plotting
ptlasso.plot_cv
plot_cv(fit, ax=None, plot_alphahat=True, column='single', save=None, colors=None, figure_widths=None)
Plot the cross-validation curve for a :class:PretrainedLassoCV.
Draws the mean CV loss ±1 SE band over alpha, with horizontal reference lines for the individual and overall baselines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
PretrainedLassoCV
|
A fitted CV estimator. |
required |
ax
|
Axes or None
|
Axes to draw on. A new figure is created when |
None
|
plot_alphahat
|
bool
|
Whether to draw a vertical line at the selected |
True
|
column
|
(single, double)
|
Target figure width — |
"single"
|
save
|
str or None
|
File path to save the figure (300 dpi). No file is written when |
None
|
colors
|
dict or None
|
Override plot colours for |
None
|
figure_widths
|
dict or None
|
Override figure widths for |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
ax |
Axes
|
|
Source code in src/ptlasso/_plot.py
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 | |
ptlasso.plot_paths
Plot regularisation paths for all sub-models in a :class:PretrainedLasso.
Produces a 3-row grid: overall model (full width), per-group pretrained models, and per-group individual models. Features in the final support are coloured; inactive features are shown in grey.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit
|
PretrainedLasso or PretrainedLassoCV
|
A fitted estimator. |
required |
column
|
(single, double)
|
Target figure width — |
"single"
|
save
|
str or None
|
File path to save the figure (300 dpi). No file is written when |
None
|
colors
|
dict or None
|
Override plot colours for |
None
|
figure_widths
|
dict or None
|
Override figure widths for |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
Source code in src/ptlasso/_plot.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
Simulation
ptlasso.make_data
make_data(k, class_sizes, s_common, s_indiv, beta_common, beta_indiv, intercepts=None, sigma=1.0, family='gaussian', seed=None)
Generate synthetic grouped data for ptlasso.
Feature layout
- Columns 0 … s_common-1 : shared features (active in all groups)
- Columns s_common … s_common+s_indiv[0]-1 : features specific to group 0
- ... and so on for each group
- Remaining columns (if any) : pure noise
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of groups. |
required |
class_sizes
|
array-like of length k
|
Number of observations per group. |
required |
s_common
|
int
|
Number of shared (common) features. |
required |
s_indiv
|
int or array-like of length k
|
Number of group-specific features per group. |
required |
beta_common
|
float or array - like
|
Coefficients for common features. Scalar → same value for all s_common features in every group. 1-D array of length s_common → per-feature coefficient (same across groups). List of k arrays → per-group, per-feature coefficients. |
required |
beta_indiv
|
float or array - like
|
Coefficients for group-specific features, same shapes as beta_common. |
required |
intercepts
|
array-like of length k or None
|
Per-group intercepts. Default is 0. |
None
|
sigma
|
float
|
Gaussian noise std (only used for |
1.0
|
family
|
(gaussian, binomial)
|
|
"gaussian"
|
seed
|
int or None
|
Random seed passed to |
None
|
Returns:
| Type | Description |
|---|---|
dict with keys
|
|
Source code in src/ptlasso/_simulate.py
ptlasso.gaussian_example_data
gaussian_example_data(k=2, class_sizes=None, s_common=5, s_indiv=5, beta_common=1.0, beta_indiv=0.5, sigma=1.0, seed=None)
Convenience wrapper for Gaussian grouped data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
|
2
|
class_sizes
|
array - like or None
|
Defaults to 50 observations per group. |
None
|
s_common
|
int
|
|
5
|
s_indiv
|
int or array - like
|
|
5
|
beta_common
|
float
|
|
1.0
|
beta_indiv
|
float
|
|
0.5
|
sigma
|
float
|
|
1.0
|
seed
|
int or None
|
|
None
|
Returns:
| Type | Description |
|---|---|
dict with keys ``X``, ``y``, ``groups``
|
|
Source code in src/ptlasso/_simulate.py
ptlasso.binomial_example_data
binomial_example_data(k=2, class_sizes=None, s_common=5, s_indiv=5, beta_common=0.5, beta_indiv=0.3, seed=None)
Convenience wrapper for binary grouped data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
|
2
|
class_sizes
|
array - like or None
|
Defaults to 100 observations per group. |
None
|
s_common
|
int
|
|
5
|
s_indiv
|
int or array - like
|
|
5
|
beta_common
|
float
|
|
0.5
|
beta_indiv
|
float
|
|
0.3
|
seed
|
int or None
|
|
None
|
Returns:
| Type | Description |
|---|---|
dict with keys ``X``, ``y``, ``groups``
|
|