import logging
import numpy as np
from sklearn import svm, datasets
from sklearn.model_selection import cross_val_score
# Import ConfigSpace and different types of parameters
from smac.configspace import ConfigurationSpace
from ConfigSpace.hyperparameters import CategoricalHyperparameter, \
UniformFloatHyperparameter, UniformIntegerHyperparameter
from ConfigSpace.conditions import InCondition
# Import SMAC-utilities
from smac.tae.execute_func import ExecuteTAFuncDict
from smac.scenario.scenario import Scenario
from smac.facade.smac_facade import SMAC
iris = datasets.load_iris()
def svm_from_cfg(cfg):
""" Creates a SVM based on a configuration and evaluates it on the
iris-dataset using cross-validation.
Parameters:
-----------
cfg: Configuration (ConfigSpace.ConfigurationSpace.Configuration)
Configuration containing the parameters.
Configurations are indexable!
Returns:
--------
A crossvalidated mean score for the svm on the loaded data-set.
"""
# For deactivated parameters, the configuration stores None-values.
# This is not accepted by the SVM, so we remove them.
cfg = {
k : cfg[k] for k in cfg if cfg[k]}
# We translate boolean values:
cfg["shrinking"] = True if cfg["shrinking"] == "true"
python-smac-svm实例
最新推荐文章于 2024-09-10 08:41:59 发布
本文介绍了如何使用Python的SMAC(Sequential Model-based Algorithm Configuration)库来优化支持向量机(SVM)的参数配置。通过示例代码展示了SMAC如何与SVM结合,以提高模型的预测性能,并探讨了这种方法在机器学习调参中的价值。
摘要由CSDN通过智能技术生成