该文件是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/。
convert_config_dict_to_choicepipeline(config_dict)
接收一个TPOT2配置字典并返回一个代表config_dict的ChoicePipeline搜索空间。
这个空间将从config_dict中包含的所有模块中进行采样。
参数:
| 名称 |
类型 |
描述 |
默认值 |
config_dict |
dict
|
|
required
|
返回:
| 类型 |
描述 |
ChoicePipeline
|
一个表示 config_dict 的 ChoicePipeline 搜索空间。
|
Source code in tpot2/old_config_utils/old_config_utils.py
| def convert_config_dict_to_choicepipeline(config_dict):
"""
Takes in a TPOT2 config dictionary and returns a ChoicePipeline search space that represents the config_dict.
This space will sample from all included modules in the config_dict.
Parameters
----------
config_dict : dict
The dictionary representation of the TPOT2 config.
Returns
-------
ChoicePipeline
A ChoicePipeline search space that represents the config_dict.
"""
search_spaces = []
for key, value in config_dict.items():
search_spaces.append(get_node_space(key, value))
return ChoicePipeline(search_spaces)
|
convert_config_dict_to_graphpipeline(config_dict)
接收一个TPOT2配置字典并返回一个表示config_dict的GraphSearchPipeline搜索空间。
此空间将从config_dict中包含的所有模块中进行采样。它还将识别分类器/回归器以设置根节点的搜索空间。
注意不要转换估计器,以便它们像在TPOT1中一样传递输入
参数:
| 名称 |
类型 |
描述 |
默认值 |
config_dict |
dict
|
|
required
|
返回:
Source code in tpot2/old_config_utils/old_config_utils.py
| def convert_config_dict_to_graphpipeline(config_dict):
"""
Takes in a TPOT2 config dictionary and returns a GraphSearchPipeline search space that represents the config_dict.
This space will sample from all included modules in the config_dict. It will also identify classifiers/regressors to set the search space for the root node.
Note doesn't convert estimators so they passthrough inputs like in TPOT1
Parameters
----------
config_dict : dict
The dictionary representation of the TPOT2 config.
Returns
-------
GraphSearchPipeline
A GraphSearchPipeline search space that represents the config_dict.
"""
root_search_spaces = []
inner_search_spaces = []
for key, value in config_dict.items():
#if root
if issubclass(load_get_module_from_string(key), sklearn.base.ClassifierMixin) or issubclass(load_get_module_from_string(key), sklearn.base.RegressorMixin):
root_search_spaces.append(get_node_space(key, value))
else:
inner_search_spaces.append(get_node_space(key, value))
if len(root_search_spaces) == 0:
Warning("No classifiers or regressors found, allowing any estimator to be the root node")
root_search_spaces = inner_search_spaces
#merge inner and root search spaces
inner_space = np.concatenate([root_search_spaces,inner_search_spaces])
root_space = ChoicePipeline(root_search_spaces)
inner_space = ChoicePipeline(inner_search_spaces)
final_space = GraphSearchPipeline(root_search_space=root_space, inner_search_space=inner_space)
return final_space
|
convert_config_dict_to_linearpipeline(config_dict)
接收一个TPOT2配置字典并返回一个表示config_dict的GraphSearchPipeline搜索空间。
此空间将从config_dict中包含的所有模块中进行采样。它还将识别分类器/回归器以设置根节点的搜索空间。
注意不要转换估计器,以便它们像在TPOT1中一样传递输入
参数:
| 名称 |
类型 |
描述 |
默认值 |
config_dict |
dict
|
|
required
|
返回:
Source code in tpot2/old_config_utils/old_config_utils.py
| def convert_config_dict_to_linearpipeline(config_dict):
"""
Takes in a TPOT2 config dictionary and returns a GraphSearchPipeline search space that represents the config_dict.
This space will sample from all included modules in the config_dict. It will also identify classifiers/regressors to set the search space for the root node.
Note doesn't convert estimators so they passthrough inputs like in TPOT1
Parameters
----------
config_dict : dict
The dictionary representation of the TPOT2 config.
Returns
-------
GraphSearchPipeline
A GraphSearchPipeline search space that represents the config_dict.
"""
root_search_spaces = []
inner_search_spaces = []
for key, value in config_dict.items():
#if root
if issubclass(load_get_module_from_string(key), sklearn.base.ClassifierMixin) or issubclass(load_get_module_from_string(key), sklearn.base.RegressorMixin):
root_search_spaces.append(get_node_space(key, value))
else:
inner_search_spaces.append(get_node_space(key, value))
if len(root_search_spaces) == 0:
Warning("No classifiers or regressors found, allowing any estimator to be the root node")
root_search_spaces = inner_search_spaces
#merge inner and root search spaces
inner_space = np.concatenate([root_search_spaces,inner_search_spaces])
root_space = ChoicePipeline(root_search_spaces)
inner_space = ChoicePipeline(inner_search_spaces)
final_space = SequentialPipeline([
DynamicLinearPipeline(inner_space, 10),
root_space
])
return final_space
|
convert_config_dict_to_list(config_dict)
接收一个TPOT2配置字典并返回一个搜索空间列表(EstimatorNode, WrapperPipeline)
参数:
| 名称 |
类型 |
描述 |
默认值 |
config_dict |
dict
|
|
required
|
返回:
| 类型 |
描述 |
list
|
表示 config_dict 的搜索空间列表(EstimatorNode, WrapperPipeline)。
|
Source code in tpot2/old_config_utils/old_config_utils.py
| def convert_config_dict_to_list(config_dict):
"""
Takes in a TPOT2 config dictionary and returns a list of search spaces (EstimatorNode, WrapperPipeline)
Parameters
----------
config_dict : dict
The dictionary representation of the TPOT2 config.
Returns
-------
list
A list of search spaces (EstimatorNode, WrapperPipeline) that represent the config_dict.
"""
search_spaces = []
for key, value in config_dict.items():
search_spaces.append(get_node_space(key, value))
return search_spaces
|
get_node_space(module_string, params)
为TPOT2配置中的单个节点创建搜索空间。
参数:
| 名称 |
类型 |
描述 |
默认值 |
module_string |
str
|
要加载的模块和类的字符串表示。例如 'sklearn.ensemble.RandomForestClassifier'
|
required
|
params |
dict
|
|
required
|
返回:
Source code in tpot2/old_config_utils/old_config_utils.py
| def get_node_space(module_string, params):
"""
Create the search space for a single node in the TPOT2 config.
Parameters
----------
module_string : str
The string representation of the module and class to load. E.g. 'sklearn.ensemble.RandomForestClassifier'
params : dict
The dictionary representation of the hyperparameter search space for the module_string.
Returns
-------
EstimatorNode or WrapperPipeline
"""
method = load_get_module_from_string(module_string)
config_space = ConfigurationSpace()
sub_space = None
sub_space_name = None
function_params_conversion_dict = {}
if params is None:
return EstimatorNode(method=method, space=config_space)
for param_name, param in params.items():
if param is None:
config_space.add(Categorical(param_name, [None]))
if isinstance(param, range):
param = list(param)
if isinstance(param, list) or isinstance(param, np.ndarray):
if len(param) == 1:
p = param[0]
config_space.add(ConfigSpace.hyperparameters.Constant(param_name, p))
else:
config_space.add(Categorical(param_name, param))
# if all(isinstance(i, int) for i in param):
# config_space.add_hyperparameter(Integer(param_name, (min(param), max(param))))
# elif all(isinstance(i, float) for i in param):
# config_space.add_hyperparameter(Float(param_name, (min(param), max(param))))
# else:
# config_space.add_hyperparameter(Categorical(param_name, param))
elif isinstance(param, dict): #TPOT1 config dicts have dictionaries for values of hyperparameters that are either a function or an estimator
if len(param) > 1:
raise ValueError(f"Multiple items in dictionary entry for {param_name}")
key = list(param.keys())[0]
innermethod = load_get_module_from_string(key)
if inspect.isclass(innermethod) and issubclass(innermethod, sklearn.base.BaseEstimator): #is an estimator
if sub_space is None:
sub_space_name = param_name
sub_space = get_node_space(key, param[key])
else:
raise ValueError("Only multiple hyperparameters are estimators. Only one parameter ")
else: #assume the key is a function and ignore the value
function_params_conversion_dict[param_name] = innermethod
else:
# config_space.add_hyperparameter(Categorical(param_name, param))
config_space.add(ConfigSpace.hyperparameters.Constant(param_name, param))
parser=None
if len(function_params_conversion_dict) > 0:
parser = partial(hyperparameter_parser, function_params_conversion_dict)
if sub_space is None:
if parser is not None:
return EstimatorNode(method=method, space=config_space, hyperparameter_parser=parser)
else:
return EstimatorNode(method=method, space=config_space)
else:
if parser is not None:
return WrapperPipeline(method=method, space=config_space, estimator_search_space=sub_space, wrapped_param_name=sub_space_name, hyperparameter_parser=parser)
else:
return WrapperPipeline(method=method, space=config_space, estimator_search_space=sub_space, wrapped_param_name=sub_space_name)
|
load_get_module_from_string(module_string)
接受一个形式为'module.submodule.class'的字符串并返回该类。
参数:
| 名称 |
类型 |
描述 |
默认值 |
module_string |
str
|
|
required
|
返回:
Source code in tpot2/old_config_utils/old_config_utils.py
| def load_get_module_from_string(module_string):
"""
Takes a string in the form of 'module.submodule.class' and returns the class.
Parameters
----------
module_string : str
The string representation of the module and class to load.
Returns
-------
class
The class that was loaded from the module string.
"""
module_name, class_name = module_string.rsplit('.', 1)
module = __import__(module_name, fromlist=[class_name])
return getattr(module, class_name)
|