gplearn如何调整符号集
时间: 2023-10-20 15:05:56 浏览: 143
GPlearn
要调整gplearn中的符号集,可以使用gplearn.genetic.SymbolicRegressor或gplearn.genetic.SymbolicTransformer中的函数set_params来修改符号集参数。例如,要使用加法、减法、乘法和除法运算符,可以将参数function_set设置为['add', 'sub', 'mul', 'div']。示例代码如下:
``` python
from gplearn.genetic import SymbolicRegressor
est = SymbolicRegressor(population_size=5000,
generations=20,
tournament_size=20,
function_set=['add', 'sub', 'mul', 'div'],
metric='rmse',
p_crossover=0.7,
p_subtree_mutation=0.1,
p_hoist_mutation=0.05,
p_point_mutation=0.1,
verbose=1,
random_state=0)
```
此外,还可以使用gplearn.genetic.SymbolicTransformer中的set_params函数来修改符号集参数。例如,要使用sin、cos和exp函数,可以将参数function_set设置为['sin', 'cos', 'exp']。示例代码如下:
``` python
from gplearn.genetic import SymbolicTransformer
est = SymbolicTransformer(population_size=5000,
generations=20,
tournament_size=20,
function_set=['sin', 'cos', 'exp'],
metric='spearman',
parsimony_coefficient=0.0005,
p_crossover=0.7,
p_subtree_mutation=0.1,
p_hoist_mutation=0.05,
p_point_mutation=0.1,
verbose=1,
random_state=0)
```
阅读全文