GeneticPy是一个使用遗传算法快速搜索自定义参数空间以找到最优解的优化器。
项目描述
GeneticPy
GeneticPy是一个使用遗传算法快速搜索自定义参数空间以找到最优解的优化器。
安装
GeneticPy需要Python 3.7+
pip install geneticpy
优化示例
以下包含一个简短的示例,以帮助您开始。
import geneticpy
def loss_function(params):
if params['type'] == 'add':
return params['x'] + params['y']
elif params['type'] == 'multiply':
return params['x'] * params['y']
param_space = {'type': geneticpy.ChoiceDistribution(choice_list=['add', 'multiply']),
'x': geneticpy.UniformDistribution(low=5, high=10, q=1),
'y': geneticpy.GaussianDistribution(mean=0, standard_deviation=1)}
results = geneticpy.optimize(loss_function, param_space, size=200, generation_count=500, verbose=True)
best_params = results['top_params']
loss = results['top_score']
total_time = results['total_time']
GeneticSearchCV 示例
您可以使用GeneticSearchCV
类作为Scikit-Learn的GridSearchCV
的替代品。这允许在使用Scikit-Learn估计器和/或管道时更快、更完整地优化超参数。
from sklearn import datasets
from sklearn.decomposition import PCA
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
from geneticpy import GeneticSearchCV, ChoiceDistribution, LogNormalDistribution, UniformDistribution
# Define a pipeline to search for the best combination of PCA truncation
# and classifier regularization.
pca = PCA()
# set the tolerance to a large value to make the example faster
logistic = LogisticRegression(max_iter=10000, tol=0.1, solver='saga')
pipe = Pipeline(steps=[('pca', pca), ('logistic', logistic)])
X_digits, y_digits = datasets.load_digits(return_X_y=True)
# Parameters of pipelines can be set using ‘__’ separated parameter names:
param_grid = {
'pca__n_components': UniformDistribution(low=5, high=64, q=1),
'logistic__C': LogNormalDistribution(mean=1, sigma=0.5, low=0.001, high=2),
'logistic__penalty': ChoiceDistribution(choice_list=['l1', 'l2'])
}
search = GeneticSearchCV(pipe, param_grid)
search.fit(X_digits, y_digits)
print("Best parameter (CV score=%0.3f):" % search.best_score_)
print(search.best_params_)
PyPi项目
https://pypi.ac.cn/project/geneticpy/
联系方式
请随时通过brandonschabell@gmail.com给我发邮件,提出任何问题或反馈。
项目详情
下载文件
下载适合您平台的应用程序。如果您不确定选择哪一个,请了解更多关于安装软件包的信息。
源代码发行版
geneticpy-1.3.0.tar.gz (11.3 kB 查看哈希值)
构建分发版
geneticpy-1.3.0-py3-none-any.whl (12.6 kB 查看哈希值)
关闭
geneticpy-1.3.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 41a21bfee92e6178505e64e14adc406be6d940e55ccb1c22f148f41db673d33e |
|
MD5 | 04875247f47d8df939630e2a5d15c0e4 |
|
BLAKE2b-256 | 67ecfaaefa7bf26b5fd3bdc7992c6388faa35eae0bc0992e81881e88979ed8f7 |
关闭
geneticpy-1.3.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 93fc994fdd66f83197303ce05b9ce6198a71d89aff0019a08daecaf8c026eded |
|
MD5 | bd72cc82fae5a0cc75901dafd99f88c9 |
|
BLAKE2b-256 | d019d9f1444965775581df0639aaab9456d863697434560ee1ae26825cff1f81 |