Created
November 13, 2018 22:56
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--------------------------------------------------------------------------- | |
ValueError Traceback (most recent call last) | |
<ipython-input-20-273b888818ab> in <module>() | |
7 | |
8 # perform tuning | |
----> 9 hps, _, _ = optunity.maximize(svm_auc, num_evals=200, logC=[-5, 2], logGamma=[-5, 1]) | |
10 | |
11 | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/api.py in maximize(f, num_evals, solver_name, pmap, **kwargs) | |
179 solver = make_solver(**suggestion) | |
180 solution, details = optimize(solver, f, maximize=True, max_evals=num_evals, | |
--> 181 pmap=pmap) | |
182 return solution, details, suggestion | |
183 | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/api.py in optimize(solver, func, maximize, max_evals, pmap, decoder) | |
243 time = timeit.default_timer() | |
244 try: | |
--> 245 solution, report = solver.optimize(f, maximize, pmap=pmap) | |
246 except fun.MaximumEvaluationsException: | |
247 # early stopping because maximum number of evaluations is reached | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/solvers/ParticleSwarm.py in optimize(self, f, maximize, pmap) | |
269 for g in range(self.num_generations): | |
270 fitnesses = pmap(evaluate, list(map(self.particle2dict, pop))) | |
--> 271 for part, fitness in zip(pop, fitnesses): | |
272 part.fitness = fit * util.score(fitness) | |
273 if not part.best or part.best_fitness < part.fitness: | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/solvers/ParticleSwarm.py in evaluate(d) | |
257 @functools.wraps(f) | |
258 def evaluate(d): | |
--> 259 return f(**d) | |
260 | |
261 if maximize: | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/functions.py in wrapped_f(*args, **kwargs) | |
299 value = wrapped_f.call_log.get(*args, **kwargs) | |
300 if value is None: | |
--> 301 value = f(*args, **kwargs) | |
302 wrapped_f.call_log.insert(value, *args, **kwargs) | |
303 return value | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/functions.py in wrapped_f(*args, **kwargs) | |
354 else: | |
355 wrapped_f.num_evals += 1 | |
--> 356 return f(*args, **kwargs) | |
357 wrapped_f.num_evals = 0 | |
358 return wrapped_f | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/constraints.py in wrapped_f(*args, **kwargs) | |
149 def wrapped_f(*args, **kwargs): | |
150 try: | |
--> 151 return f(*args, **kwargs) | |
152 except ConstraintViolation: | |
153 return default | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/constraints.py in wrapped_f(*args, **kwargs) | |
127 if violations: | |
128 raise ConstraintViolation(violations, *args, **kwargs) | |
--> 129 return f(*args, **kwargs) | |
130 wrapped_f.constraints = constraints | |
131 return wrapped_f | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/constraints.py in func(*args, **kwargs) | |
264 @functions.wraps(f) | |
265 def func(*args, **kwargs): | |
--> 266 return f(*args, **kwargs) | |
267 return func | |
268 | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/cross_validation.py in __call__(self, *args, **kwargs) | |
401 kwargs['y_train'] = select(self.y, rows_train) | |
402 kwargs['y_test'] = select(self.y, rows_test) | |
--> 403 scores.append(self.f(**kwargs)) | |
404 return self.reduce(scores) | |
405 | |
<ipython-input-20-273b888818ab> in svm_auc(x_train, y_train, x_test, y_test, logC, logGamma) | |
4 model = sklearn.svm.SVC(C=10 ** logC, gamma=10 ** logGamma).fit(x_train, y_train) | |
5 decision_values = model.decision_function(x_test) | |
----> 6 return optunity.metrics.roc_auc(y_test, decision_values) | |
7 | |
8 # perform tuning | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/metrics.py in roc_auc(ys, yhat, positive, presorted, return_curve) | |
408 | |
409 """ | |
--> 410 curve = compute_curve(ys, yhat, _fpr, _recall, positive) | |
411 if return_curve: | |
412 return auc(curve), curve | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/metrics.py in compute_curve(ys, decision_values, xfun, yfun, positive, presorted) | |
130 """ | |
131 curve = [] | |
--> 132 tables, _ = contingency_tables(ys, decision_values, positive, presorted) | |
133 curve = list(map(lambda t: (xfun(t), yfun(t)), tables)) | |
134 return curve | |
/opt/conda/envs/DSX-Python35/lib/python3.5/site-packages/optunity/metrics.py in contingency_tables(ys, decision_values, positive, presorted) | |
71 # sort decision values | |
72 ind, srt = zip(*sorted(enumerate(decision_values), reverse=True, | |
---> 73 key=op.itemgetter(1))) | |
74 | |
75 # resort y | |
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment