估计器
此文件是 TPOT 库的一部分。
当前版本的 TPOT 由 Cedars-Sinai 的以下人员开发: - Pedro Henrique Ribeiro (https://github.com/perib, https://www.linkedin.com/in/pedro-ribeiro/) - Anil Saini (anil.saini@cshs.org) - Jose Hernandez (jgh9094@gmail.com) - Jay Moran (jay.moran@cshs.org) - Nicholas Matsumoto (nicholas.matsumoto@cshs.org) - Hyunjun Choi (hyunjun.choi@cshs.org) - Gabriel Ketron (gabriel.ketron@cshs.org) - Miguel E. Hernandez (miguel.e.hernandez@cshs.org) - Jason Moore (moorejh28@gmail.com)
TPOT 的原始版本主要由宾夕法尼亚大学的以下人员开发: - Randal S. Olson (rso@randalolson.com) - Weixuan Fu (weixuanf@upenn.edu) - Daniel Angell (dpa34@drexel.edu) - Jason Moore (moorejh28@gmail.com) - 以及许多慷慨的开源贡献者
TPOT 是免费软件:您可以根据自由软件基金会发布的 GNU 宽通用公共许可证(第三版或您选择的任何更高版本)的条款重新分发和/或修改它。
分发 TPOT 是希望它有用,但没有任何担保;甚至不包括适销性或特定用途适用性的默示担保。有关更多详细信息,请参阅 GNU 宽通用公共许可证。
您应该随 TPOT 一起收到了 GNU 宽通用公共许可证的副本。如果没有,请参阅 https://gnu.ac.cn/licenses/。
TPOTEstimator
¶
基类: BaseEstimator
源代码位于 tpot/tpot_estimator/estimator.py
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 |
|
classes_
property
¶
类别标签。仅当最后一步是分类器时存在。
__init__(search_space, scorers, scorers_weights, classification, cv=10, other_objective_functions=[], other_objective_functions_weights=[], objective_function_names=None, bigger_is_better=True, export_graphpipeline=False, memory=None, categorical_features=None, preprocessing=False, population_size=50, initial_population_size=None, population_scaling=0.5, generations_until_end_population=1, generations=None, max_time_mins=60, max_eval_time_mins=10, validation_strategy='none', validation_fraction=0.2, disable_label_encoder=False, early_stop=None, scorers_early_stop_tol=0.001, other_objectives_early_stop_tol=None, threshold_evaluation_pruning=None, threshold_evaluation_scaling=0.5, selection_evaluation_pruning=None, selection_evaluation_scaling=0.5, min_history_threshold=20, survival_percentage=1, crossover_probability=0.2, mutate_probability=0.7, mutate_then_crossover_probability=0.05, crossover_then_mutate_probability=0.05, survival_selector=survival_select_NSGA2, parent_selector=tournament_selection_dominated, budget_range=None, budget_scaling=0.5, generations_until_end_budget=1, stepwise_steps=5, n_jobs=1, memory_limit=None, client=None, processes=True, warm_start=False, periodic_checkpoint_folder=None, callback=None, verbose=0, scatter=True, random_state=None)
¶
一个使用遗传编程优化管道的 sklearn 基本估计器。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
search_space |
(字符串, SearchSpace)
|
请注意,TPOT MDR 运行可能很慢,因为特征选择例程计算开销很大,尤其是在大型数据集上。|
|
必需的 |
scorers |
(列表, 评分器)
|
用于交叉验证过程的一个或多个评分器。请参阅 https://scikit-learn.cn/stable/modules/model_evaluation.html |
必需的 |
scorers_weights |
列表
|
在优化过程中应用于评分器的权重列表。 |
必需的 |
classification |
布尔值
|
如果为 True,则问题被视为分类问题。如果为 False,则问题被视为回归问题。用于确定交叉验证策略。 |
必需的 |
cv |
(整数, 交叉 - 验证器)
|
|
10
|
other_objective_functions |
列表
|
应用于管道的其他目标函数列表。函数接受 graphpipeline 估计器的一个参数,并返回单个分数或分数列表。 |
[]
|
other_objective_functions_weights |
列表
|
应用于其他目标函数的权重列表。 |
[]
|
objective_function_names |
列表
|
应用于目标函数的名称列表。如果为 None,将使用目标函数本身的名称。 |
无
|
bigger_is_better |
布尔值
|
如果为 True,则最大化目标函数。如果为 False,则最小化目标函数。使用负权重可以反转方向。 |
True
|
memory |
如果提供,管道将在调用 fit 方法后使用 joblib.Memory 缓存每个转换器。此功能用于避免在优化过程中,当参数和输入数据与另一个已拟合的管道相同时,重新计算管道内的已拟合转换器。- 字符串 'auto':TPOT 使用临时目录进行内存缓存,并在关闭时清除。- 字符串路径:TPOT 使用提供的目录进行内存缓存,并且在关闭时不会清除该缓存目录。如果目录不存在,TPOT 将创建它。- Memory 对象:TPOT 使用 joblib.Memory 的实例进行内存缓存,并且在关闭时不会清除该缓存目录。- None:TPOT 不使用内存缓存。 |
无
|
|
categorical_features |
在预处理步骤中需要填补和/或进行独热编码的分类列。仅当 preprocessing 不为 False 时使用。- None:如果为 None,TPOT 将自动使用 pandas DataFrames 中的 object 列作为预处理中的独热编码对象。- 分类特征列表。如果 X 是 DataFrame,这应该是一个列名列表。如果 X 是 numpy 数组,这应该是一个列索引列表。 |
无
|
|
preprocessing |
(布尔值 或 BaseEstimator / 管道)
|
实验性功能 - 未来版本可能会更改 用于在交叉验证之前预处理数据的管道。请注意,这些步骤的参数不会被优化。将它们添加到搜索空间中才能进行优化。- 布尔值:如果为 True,将使用默认的预处理管道,包括填补和独热编码。- 管道:如果提供了管道实例,将使用该管道作为预处理管道。 |
False
|
population_size |
整数
|
种群大小 |
50
|
initial_population_size |
整数
|
初始种群大小。如果为 None,将使用 population_size。 |
无
|
population_scaling |
整数
|
用于确定阈值从起始百分位数移动到结束百分位数的快慢的缩放因子。 |
0.5
|
generations_until_end_population |
整数
|
种群大小达到 population_size 所需的代数 |
1
|
generations |
整数
|
运行的代数 |
50
|
max_time_mins |
浮点数
|
优化运行的最大时间(分钟)。如果为 None 或 inf,将运行直到代数结束。 |
float("inf")
|
max_eval_time_mins |
浮点数
|
评估单个个体的最大时间(分钟)。如果为 None 或 inf,每次评估将没有时间限制。 |
5
|
validation_strategy |
字符串
|
实验性功能 用于从种群中选择最终管道的验证策略。TPOT 可能会过拟合交叉验证分数。可以使用第二个验证集来选择最终管道。- 'auto':根据数据集形状自动确定验证策略。- 'reshuffled':使用相同数据进行交叉验证和最终验证,但折叠划分不同。这是小型数据集的默认设置。- 'split':使用单独的验证集进行最终验证。数据将根据 validation_fraction 进行分割。这是中型数据集的默认设置。- 'none':不使用单独的验证集进行最终验证。根据原始交叉验证分数进行选择。这是大型数据集的默认设置。 |
'none'
|
validation_fraction |
浮点数
|
实验性功能 当 validation_strategy 为 'split' 时,用于验证集的数据集比例。必须介于 0 和 1 之间。 |
0.2
|
disable_label_encoder |
布尔值
|
如果为 True,TPOT 将检查目标是否需要重新标记为从 0 到 N 的连续整数。这对于 XGBoost 兼容性是必需的。如果标签需要编码,TPOT 将使用 sklearn.preprocessing.LabelEncoder 对标签进行编码。编码器可以通过 self.label_encoder_ 属性访问。如果为 False,则不使用额外的标签编码器。 |
False
|
early_stop |
整数
|
在早停之前没有改进的代数。所有目标必须在容差范围内收敛才能触发此功能。通常 5-20 左右的值比较好。 |
无
|
scorers_early_stop_tol |
-浮点数列表 每个评分器的容差列表。如果最佳分数与当前分数之间的差小于容差,则认为个体已收敛。如果列表中的某个索引为 None,则该项不用于早停。-整数 如果给定一个整数,它将用作所有目标的容差。 |
0.001
|
|
other_objectives_early_stop_tol |
-浮点数列表 每个其他目标函数的容差列表。如果最佳分数与当前分数之间的差小于容差,则认为个体已收敛。如果列表中的某个索引为 None,则该项不用于早停。-整数 如果给定一个整数,它将用作所有目标的容差。 |
无
|
|
threshold_evaluation_pruning |
列表[开始, 结束]
|
用于评估早停阈值的起始和结束百分位数。值介于 0 和 100 之间。 |
无
|
threshold_evaluation_scaling |
浮点数 [0,inf)
|
用于确定阈值从起始百分位数移动到结束百分位数的快慢的缩放因子。必须大于零。数值越大,阈值移动到结束的速度越快。 |
0.5
|
selection_evaluation_pruning |
列表
|
在每轮交叉验证中选择的种群大小的下限和上限百分比。值介于 0 和 1 之间。 |
无
|
selection_evaluation_scaling |
浮点数
|
用于确定阈值从起始百分位数移动到结束百分位数的快慢的缩放因子。必须大于零。数值越大,阈值移动到结束的速度越快。 |
0.5
|
min_history_threshold |
整数
|
使用阈值早停前所需的最小历史分数数量。 |
0
|
survival_percentage |
浮点数
|
在每代开始时用于变异和交叉的种群大小百分比。其余个体将被丢弃。个体使用传递给 survival_selector 的选择器进行选择。此参数的值必须介于 0 和 1 之间(含)。例如,如果种群大小为 100,存活率为 0.5,则将从现有种群中通过 NSGA2 选择 50 个个体。这些个体将用于变异和交叉,以生成下一代的 100 个个体。其余的个体将从活跃种群中丢弃。下一代将有 50 个父代个体 + 100 个个体,总共 150 个。存活百分比基于 population_size 参数,而不是现有种群大小(使用逐次减半时的当前种群大小)。因此,在下一代中,我们仍将从当前存在的 150 个个体中选择 50 个个体。 |
1
|
crossover_probability |
浮点数
|
通过两个个体交叉生成新个体的概率。 |
.2
|
mutate_probability |
浮点数
|
通过对一个个体进行变异生成新个体的概率。 |
.7
|
mutate_then_crossover_probability |
浮点数
|
通过对两个个体进行变异然后进行交叉生成新个体的概率。 |
.05
|
crossover_then_mutate_probability |
浮点数
|
通过对两个个体进行交叉然后对结果个体进行变异生成新个体的概率。 |
.05
|
survival_selector |
函数
|
用于选择存活个体的函数。必须接受一个分数矩阵并返回选定的索引。用于在每代开始时选择 population_size * survival_percentage 个个体进行变异和交叉。 |
survival_select_NSGA2
|
parent_selector |
函数
|
用于选择交叉父代对和变异个体的函数。必须接受一个分数矩阵并返回选定的索引。 |
parent_select_NSGA2
|
budget_range |
列表[开始, 结束]
|
用于预算缩放的起始和结束预算。 |
无
|
budget_scaling |
用于确定预算从起始预算移动到结束预算的快慢的缩放因子。 |
0.5
|
|
generations_until_end_budget |
整数
|
达到最大预算前运行的代数。 |
1
|
stepwise_steps |
整数
|
缩放预算和种群大小时采取的阶梯步数。 |
1
|
n_jobs |
整数
|
并行运行的进程数。 |
1
|
memory_limit |
字符串
|
每个作业的内存限制。更多信息请参阅 Dask LocalCluster 文档。 |
无
|
client |
客户端
|
用于并行化的 Dask 客户端。如果不为 None,将覆盖 n_jobs 和 memory_limit 参数。如果为 None,将创建一个 num_workers=n_jobs 和 memory_limit=memory_limit 的新客户端。 |
无
|
processes |
布尔值
|
如果为 True,将使用多进程并行化优化过程。如果为 False,将使用多线程。True 的性能似乎更好。但是,交互式调试需要 False。 |
True
|
warm_start |
布尔值
|
如果为 True,将从上次运行的最后一代替续进化算法。 |
False
|
periodic_checkpoint_folder |
字符串
|
定期保存种群的文件夹。如果为 None,则不进行定期保存。如果提供,训练将从该检查点恢复。 |
无
|
callback |
CallBackInterface
|
回调对象。未实现 |
无
|
verbose |
整数
|
优化过程中打印的信息量。值越高包含的信息越多。0. 无 1. 进度条
|
1
|
scatter |
布尔值
|
如果为 True,将把数据分散到 Dask worker。如果为 False,则不分散数据。这对于调试可能很有用。 |
True
|
random_state |
(整数, None)
|
用于实验重现性的种子。此值将传递给 numpy.random.default_rng() 以创建生成器实例,然后传递给其他类。
|
无
|
属性
名称 | 类型 | 描述 |
---|---|---|
fitted_pipeline_ |
GraphPipeline
|
已拟合的 GraphPipeline 实例,继承自 sklearn BaseEstimator。它在传递给 fit 的完整 X, y 上进行拟合。 |
evaluated_individuals |
一个 pandas DataFrame,包含运行中所有已评估个体的数据。
|
列: - *目标函数:前几列对应于传入的评分器和其他目标函数。- Parents:一个元组,包含用于生成该行管道的父管道的索引。如果为 NaN,则该管道是在初始种群中随机生成的。- Variation_Function:用于变异或交叉父代的变异函数。如果为 NaN,则该管道是在初始种群中随机生成的。- Individual:在进化算法中使用的个体的内部表示。这不是 sklearn BaseEstimator。- Generation:管道首次出现的代数。- Pareto_Front:该管道所属的非支配前沿。0 表示其得分未被任何其他个体严格支配。为了节省计算时间,最佳前沿在每代迭代更新。Pareto_Front 为 0 的管道确实代表了精确的最佳前沿。但是,Pareto_Front >= 1 的管道仅参照最终种群中的其他管道。所有其他管道都设置为 NaN。- Instance:未拟合的 GraphPipeline BaseEstimator 实例。- *验证目标函数:在验证集上评估的目标函数分数。- Validation_Pareto_Front:在验证集上计算的完整 Pareto 前沿。这针对所有 Pareto_Front 等于 0 的管道计算。与仅计算前沿和最终种群的 Pareto_Front 不同,Validation Pareto Front 针对所有在验证集上测试过的管道进行计算。 |
pareto_front |
与 evaluated_individuals 相同的 pandas DataFrame,但仅包含前沿 Pareto 前沿管道。
|
|
源代码位于 tpot/tpot_estimator/estimator.py
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 |
|
apply_make_pipeline(ind, preprocessing_pipeline=None, export_graphpipeline=False, **pipeline_kwargs)
¶
辅助函数,用于从 tpot individual 类创建 sklearn 管道列。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
ind |
要转换为管道的个体。 |
必需的 | |
preprocessing_pipeline |
要包含在个体管道之前的预处理管道。 |
无
|
|
export_graphpipeline |
强制将管道导出为图形管道。将所有嵌套的管道、FeatureUnions 和 GraphPipelines 展平为一个单独的 GraphPipeline。 |
False
|
|
pipeline_kwargs |
传递给 export_pipeline 或 export_flattened_graphpipeline 方法的关键字参数。 |
{}
|
返回
类型 | 描述 |
---|---|
sklearn 估计器
|
|
源代码位于 tpot/tpot_estimator/estimator_utils.py
check_empty_values(data)
¶
检查数据集中是否存在空值。
Args: data (numpy.ndarray 或 pandas.DataFrame):要检查的数据集。
Returns: 布尔值:如果数据集包含空值,则为 True;否则为 False。
源代码位于 tpot/tpot_estimator/estimator.py
check_if_y_is_encoded(y)
¶
检查目标 y 是否由从 0 到 N 的连续整数组成。XGBoost 要求目标以此方式编码。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
y |
目标向量。 |
必需的 |
返回
类型 | 描述 |
---|---|
布尔值
|
如果目标编码为从 0 到 N 的连续整数,则为 True;否则为 False |
源代码位于 tpot/tpot_estimator/estimator_utils.py
convert_parents_tuples_to_integers(row, object_to_int)
¶
辅助函数,用于将父行转换为表示种群中父代索引的整数。
原始的 pandas DataFrame,使用自定义索引表示父代。此函数将自定义索引转换为整数索引,方便最终用户操作。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
row |
要转换的行。 |
必需的 | |
object_to_int |
将对象映射到整数索引的字典。 |
必需的 |
返回
元组 包含自定义索引转换为整数索引的行。
源代码位于 tpot/tpot_estimator/estimator_utils.py
cross_val_score_objective(estimator, X, y, scorers, cv, fold=None)
¶
计算估计器的交叉验证分数。每个折叠仅拟合估计器一次,并遍历评分器以评估估计器。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
估计器 |
要拟合和评分的估计器。 |
必需的 | |
X |
特征矩阵。 |
必需的 | |
y |
目标向量。 |
必需的 | |
scorers |
要使用的评分器。如果是一个列表,将遍历评分器并返回一个评分器列表。如果是一个评分器,将返回单个分数。 |
必需的 | |
cv |
要使用的交叉验证器。例如,sklearn.model_selection.KFold 或 sklearn.model_selection.StratifiedKFold。 |
必需的 | |
fold |
返回分数的折叠。如果为 None,将返回所有分数(每个评分器)的平均值。默认为 None。 |
无
|
返回
名称 | 类型 | 描述 |
---|---|---|
scores |
numpy 数组 或 浮点数
|
估计器每个评分器的分数。如果 fold 为 None,将返回所有分数(每个评分器)的平均值。如果使用多个评分器,返回一个列表,否则返回单个评分器的浮点数。 |
源代码位于 tpot/tpot_estimator/cross_val_utils.py
objective_function_generator(pipeline, x, y, scorers, cv, other_objective_functions, step=None, budget=None, is_classification=True, export_graphpipeline=False, **pipeline_kwargs)
¶
使用交叉验证通过评分器评估管道,并将结果与独立的其他目标函数的分数连接起来。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
pipeline |
要评估的个体。 |
必需的 | |
x |
特征矩阵。 |
必需的 | |
y |
目标向量。 |
必需的 | |
scorers |
用于交叉验证的评分器。 |
必需的 | |
cv |
要使用的交叉验证器。例如,sklearn.model_selection.KFold 或 sklearn.model_selection.StratifiedKFold。如果是一个整数,将使用 n_splits=cv 的 sklearn.model_selection.KFold。 |
必需的 | |
other_objective_functions |
用于评估管道的独立目标函数列表。函数签名 obj(pipeline) -> float 或 obj(pipeline) -> np.ndarray。这些函数接受未拟合的估计器。 |
必需的 | |
step |
返回分数的折叠。如果为 None,将返回所有分数(每个评分器)的平均值。默认为 None。 |
无
|
|
budget |
用于对数据进行子抽样的预算。如果为 None,将使用完整数据集。默认为 None。将抽取 budget*len(x) 个样本。 |
无
|
|
is_classification |
如果为 True,将对子抽样进行分层。默认为 True。 |
True
|
|
export_graphpipeline |
强制将管道导出为图形管道。将所有嵌套的 sklearn 管道、FeatureUnions 和 GraphPipelines 展平为一个单独的 GraphPipeline。 |
False
|
|
pipeline_kwargs |
传递给 export_pipeline 或 export_flattened_graphpipeline 方法的关键字参数。 |
{}
|
返回
类型 | 描述 |
---|---|
ndarray
|
管道的连接分数。前 len(scorers) 个元素是交叉验证分数,其余元素是独立目标函数的分数。 |
源代码位于 tpot/tpot_estimator/estimator_utils.py
remove_underrepresented_classes(x, y, min_count)
¶
辅助函数,用于从数据集中移除样本数少于 min_count 的类别。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
x |
特征矩阵。 |
必需的 | |
y |
目标向量。 |
必需的 | |
min_count |
保留类别的最小样本数。 |
必需的 |
返回
类型 | 描述 |
---|---|
(numpy 数组, numpy 数组)
|
移除样本数少于 min_count 的类别对应行的特征矩阵和目标向量。 |
源代码位于 tpot/tpot_estimator/estimator_utils.py
val_objective_function_generator(pipeline, X_train, y_train, X_test, y_test, scorers, other_objective_functions, export_graphpipeline=False, **pipeline_kwargs)
¶
在训练集上训练管道,并使用评分器和其他目标函数在测试集上评估它。
参数
名称 | 类型 | 描述 | 默认值 |
---|---|---|---|
pipeline |
要评估的个体。 |
必需的 | |
X_train |
训练集的特征矩阵。 |
必需的 | |
y_train |
训练集的目标向量。 |
必需的 | |
X_test |
测试集的特征矩阵。 |
必需的 | |
y_test |
测试集的目标向量。 |
必需的 | |
scorers |
用于交叉验证的评分器。 |
必需的 | |
other_objective_functions |
用于评估管道的独立目标函数列表。函数签名 obj(pipeline) -> float 或 obj(pipeline) -> np.ndarray。这些函数接受未拟合的估计器。 |
必需的 | |
export_graphpipeline |
强制将管道导出为图形管道。将所有嵌套的 sklearn 管道、FeatureUnions 和 GraphPipelines 展平为一个单独的 GraphPipeline。 |
False
|
|
pipeline_kwargs |
传递给 export_pipeline 或 export_flattened_graphpipeline 方法的关键字参数。 |
{}
|
返回
类型 | 描述 |
---|---|
ndarray
|
管道的连接分数。前 len(scorers) 个元素是交叉验证分数,其余元素是独立目标函数的分数。 |