估计器工具
该文件是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) - 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 宽通用公共许可证的条款重新分发和/或修改它,许可证的版本可以是第 3 版,或者(根据您的选择)任何以后的版本。
TPOT 的发布是希望它能有用, 但没有任何保证;甚至没有对 适销性或特定用途适用性的暗示保证。更多详情请参阅 GNU 较宽松通用公共许可证。
您应该已经收到了一份GNU较宽松通用公共许可证的副本,随TPOT一起提供。如果没有,请参见http://www.gnu.org/licenses/。
apply_make_pipeline(ind, preprocessing_pipeline=None, export_graphpipeline=False, **pipeline_kwargs)
¶
辅助函数,用于从tpot2个体类创建sklearn管道的列。
参数:
| 名称 | 类型 | 描述 | 默认值 |
|---|---|---|---|
ind |
要转换为管道的个体。 |
required | |
preprocessing_pipeline |
在个体的管道之前包含的预处理管道。 |
None
|
|
export_graphpipeline |
强制将管道导出为图形管道。将所有嵌套的管道、FeatureUnions 和 GraphPipelines 展平为单个 GraphPipeline。 |
False
|
|
pipeline_kwargs |
传递给 export_pipeline 或 export_flattened_graphpipeline 方法的关键字参数。 |
{}
|
返回:
| 类型 | 描述 |
|---|---|
sklearn estimator
|
|
Source code in tpot2/tpot_estimator/estimator_utils.py
check_if_y_is_encoded(y)
¶
检查目标 y 是否由从 0 到 N 的连续整数组成。 XGBoost 要求目标以这种方式编码。
参数:
| 名称 | 类型 | 描述 | 默认值 |
|---|---|---|---|
y |
目标向量。 |
必填 |
返回:
| 类型 | 描述 |
|---|---|
bool
|
如果目标被编码为从0到N的顺序整数,则为True,否则为False |
Source code in tpot2/tpot_estimator/estimator_utils.py
convert_parents_tuples_to_integers(row, object_to_int)
¶
辅助函数,用于将父行转换为表示父代在种群中索引的整数。
使用自定义索引的原始pandas数据框。此函数将自定义索引转换为整数索引,以便最终用户更容易操作。
参数:
| 名称 | 类型 | 描述 | 默认值 |
|---|---|---|---|
row |
要转换的行。 |
必填 | |
object_to_int |
一个将对象映射到整数索引的字典。 |
required |
Returns
元组 带有自定义索引的行已转换为整数索引。
Source code in tpot2/tpot_estimator/estimator_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 |
要评估的个体。 |
required | |
x |
特征矩阵。 |
必填 | |
y |
目标向量。 |
必填 | |
scorers |
用于交叉验证的评分器。 |
必填 | |
cv |
使用的交叉验证器。例如,sklearn.model_selection.KFold 或 sklearn.model_selection.StratifiedKFold。 如果是一个整数,将使用 sklearn.model_selection.KFold 并设置 n_splits=cv。 |
required | |
other_objective_functions |
用于评估管道的独立目标函数列表。签名格式为 obj(pipeline) -> float 或 obj(pipeline) -> np.ndarray 这些函数接收未拟合的估计器。 |
required | |
step |
要返回分数的折叠。如果为None,将返回所有分数的平均值(每个评分器)。默认值为None。 |
None
|
|
budget |
用于对数据进行子采样的预算。如果为None,将使用完整的数据集。默认值为None。 将子采样budget*len(x)个样本。 |
None
|
|
is_classification |
如果为True,将进行分层子采样。默认为True。 |
True
|
|
export_graphpipeline |
强制将管道导出为图形管道。将所有嵌套的sklearn管道、FeatureUnions和GraphPipelines展平为单个GraphPipeline。 |
False
|
|
pipeline_kwargs |
传递给 export_pipeline 或 export_flattened_graphpipeline 方法的关键字参数。 |
{}
|
返回:
| 类型 | 描述 |
|---|---|
ndarray
|
管道的连接分数。前 len(scorers) 个元素是交叉验证分数,其余元素是独立的目标函数。 |
Source code in tpot2/tpot_estimator/estimator_utils.py
remove_underrepresented_classes(x, y, min_count)
¶
辅助函数,用于从数据集中移除样本数少于min_count的类别。
参数:
| 名称 | 类型 | 描述 | 默认值 |
|---|---|---|---|
x |
特征矩阵。 |
必填 | |
y |
目标向量。 |
必填 | |
min_count |
保留一个类别所需的最小样本数。 |
required |
返回:
| 类型 | 描述 |
|---|---|
(ndarray, ndarray)
|
特征矩阵和目标向量,其中移除了样本数少于min_count的类别的行。 |
Source code in tpot2/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 |
要评估的个体。 |
required | |
X_train |
训练集的特征矩阵。 |
required | |
y_train |
训练集的目标向量。 |
required | |
X_test |
测试集的特征矩阵。 |
required | |
y_test |
测试集的目标向量。 |
required | |
scorers |
用于交叉验证的评分器。 |
必填 | |
other_objective_functions |
用于评估管道的独立目标函数列表。签名格式为 obj(pipeline) -> float 或 obj(pipeline) -> np.ndarray 这些函数接收未拟合的估计器。 |
required | |
export_graphpipeline |
强制将管道导出为图形管道。将所有嵌套的sklearn管道、FeatureUnions和GraphPipelines展平为单个GraphPipeline。 |
False
|
|
pipeline_kwargs |
传递给 export_pipeline 或 export_flattened_graphpipeline 方法的关键字参数。 |
{}
|
返回:
| 类型 | 描述 |
|---|---|
ndarray
|
管道的连接分数。前 len(scorers) 个元素是交叉验证分数,其余元素是独立的目标函数。 |