我没有运行玩具示例,以下代码可以正常工作
import optunity
import optunity.metrics
import sklearn.svm
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
# import some data to play with
iris = datasets.load_iris()
# Take the first two features. We could avoid this by using a two-dim dataset
data = iris.data
optimal_model = sklearn.svm.SVC(C=1, gamma=10).fit(data, labels)
但是在开始超参数调整时,以下代码会导致问题
# score function: twice iterated 10-fold cross-validated accuracy
@optunity.cross_validated(x=data, y=labels, num_folds=10, num_iter=2)
def svm_auc(x_train, y_train, x_test, y_test, logC, logGamma):
model = sklearn.svm.SVC(C=10 ** logC, gamma=10 ** logGamma).fit(x_train, y_train)
decision_values = model.decision_function(x_test)
return optunity.metrics.roc_auc(y_test, decision_values)
# perform tuning
hps, _, _ = optunity.maximize(svm_auc, num_evals=200, logC=[-5, 2], logGamma=[-5, 1])
# train model on the full training set with tuned hyperparameters
optimal_model = sklearn.svm.SVC(C=10 ** hps['logC'], gamma=10 ** hps['logGamma']).fit(data, labels)
这是错误:
https://gist.github.com/romeokienzler/1034e8af4bce6926d9b961e41a98e1a4