[Python] ConfigSpace 여러 기능 사용해보기
2020. 8. 20. 21:20ㆍ분석 Python/구현 및 자료
import ConfigSpace as CS
config_space = CS.ConfigurationSpace()
config_space.add_hyperparameter(
CS.UniformIntegerHyperparameter('hidden_size_1', lower=50, upper=100))
config_space.add_hyperparameter(
CS.UniformIntegerHyperparameter('hidden_size_2', lower=10, upper=50))
# config_space.add_hyperparameter(
# CS.UniformIntegerHyperparameter('hidden_size_3', lower=10, upper=100))
config_space.add_hyperparameter(
CS.UniformFloatHyperparameter("lr", lower=1e-6,upper =1e-2,log=True))
config_space.add_hyperparameter(
CS.UniformFloatHyperparameter("weight_decay", lower=1e-7,upper =1e-3,log=True))
config_space.add_hyperparameter(
CS.CategoricalHyperparameter('activation', choices=['selu', 'leaky_relu', 'elu',"prelu","gelu"]))
config_space.sample_configuration()
Integer hyperparameters and float hyperparameters
config_space = CS.ConfigurationSpace()
config_space.add_hyperparameter(
CS.UniformFloatHyperparameter(name='C', lower=-1, upper=1,log=False))
config_space.add_hyperparameter(
CS.UniformIntegerHyperparameter(name='max_iter', lower=10, upper=100,))
config_space.sample_configuration()
Categorical hyperparameters and conditions
config_space = CS.ConfigurationSpace(seed=1234)
kernel_type = CS.CategoricalHyperparameter(
name='kernel_type', choices=['linear', 'poly', 'rbf', 'sigmoid'])
degree = CS.UniformIntegerHyperparameter(
'degree', lower=2, upper=4, default_value=2)
coef0 = CS.UniformFloatHyperparameter(
name='coef0', lower=0, upper=1, default_value=0.0)
gamma = CS.UniformFloatHyperparameter(
name='gamma', lower=1e-5, upper=1e2, default_value=1, log=True)
config_space.add_hyperparameters([kernel_type, degree, coef0, gamma])
config_space.sample_configuration()
cond_1 = CS.EqualsCondition(degree, kernel_type, 'poly')
cond_2 = CS.OrConjunction(CS.EqualsCondition(coef0, kernel_type, 'poly'),
CS.EqualsCondition(coef0, kernel_type, 'sigmoid'))
cond_3 = CS.OrConjunction(CS.EqualsCondition(gamma, kernel_type, 'rbf'),
CS.EqualsCondition(gamma, kernel_type, 'poly'),
CS.EqualsCondition(gamma, kernel_type, 'sigmoid'))
config_space.add_conditions([cond_2])
kernel_type이 poly일 때나 sigmoid일 때 coef를 사용함.
config_space.sample_configuration()
Forbidden clauses
config_space = CS.ConfigurationSpace()
penalty = CS.CategoricalHyperparameter(
name="penalty", choices=["l1", "l2"], default_value="l2")
loss = CS.CategoricalHyperparameter(
name="loss", choices=["hinge", "squared_hinge"], default_value="squared_hinge")
dual = CS.Constant("dual", "False")
config_space.add_hyperparameters([penalty, loss, dual])
config_space.sample_configuration()
penalty_and_loss = CS.ForbiddenAndConjunction(
CS.ForbiddenEqualsClause(penalty, "l1"),
CS.ForbiddenEqualsClause(loss, "hinge")
)
constant_penalty_and_loss = CS.ForbiddenAndConjunction(
CS.ForbiddenEqualsClause(dual, "False"),
CS.ForbiddenEqualsClause(penalty, "l2"),
CS.ForbiddenEqualsClause(loss, "hinge")
)
penalty_and_dual = CS.ForbiddenAndConjunction(
CS.ForbiddenEqualsClause(dual, "False"),
CS.ForbiddenEqualsClause(penalty, "l1")
)
config_space.add_forbidden_clauses([penalty_and_loss,
constant_penalty_and_loss,
penalty_and_dual])
- penalty가 l1 이면서 loss가 hinge 인 것은 금지
- dual이 False면서 penalty가 l2 이면서 loss가 hinge 인 것은 금지
- dual이 False면서, penalty가 l1 이면 금지
config_space.sample_configuration()
https://automl.github.io/ConfigSpace/master/API-Doc.html#hyperparameters
728x90
'분석 Python > 구현 및 자료' 카테고리의 다른 글
[Python] dictionary filter (0) | 2020.09.12 |
---|---|
[Python] re.sub에서 특정한 것만 바꾸고 싶을 때 하는 방법 (0) | 2020.08.26 |
[Python] 딥러닝 학습하는 도중에 GPU 사용량 확인하기 (1) | 2020.08.19 |
[Python] H2O로 Randomforest 해보기 (0) | 2020.08.10 |
dict을 txt 저장했을 때 다시 dict으로 만들기 (0) | 2020.07.09 |