this is my function wich need to be maximized
`
def performance_lr(x_train, y_train, x_test, y_test, penalty=None, tol=None, C=None, intercept_scaling=None, solver=None):
def mapper(f, breakpoint=[], cat=[]):
return cat[bisect(breakpoint, f)]
penalty=mapper(penalty, breakpoint=[0.25, 0.5, 0.75],
cat=['none', 'l1', 'l2', 'elasticnet'])
solver=mapper(solver, breakpoint=[0.2, 0.4, 0.6, 0.8], cat=['newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga'])
print(f'penalty:{penalty}, solver:{solver}')
model = LogisticRegression(penalty=penalty, tol=tol, C=C,
intercept_scaling=intercept_scaling,
solver=solver, n_jobs=-1, random_state=42)
scores = np.mean(cross_val_score(model, X, y, cv=3, n_jobs=-1,
scoring='accuracy'))
`
but there seems to an error to come which is
`
TypeError Traceback (most recent call last)
in
----> 1 optimal_confg, info, _ = optunity.maximize(performance_lr,
2 solver_name='particle swarm',
3 num_evals=50,
4 **search)
/usr/local/lib/python3.8/dist-packages/optunity/api.py in maximize(f, num_evals, solver_name, pmap, **kwargs)
178 suggestion = suggest_solver(num_evals, solver_name, **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
/usr/local/lib/python3.8/dist-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
/usr/local/lib/python3.8/dist-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:
/usr/local/lib/python3.8/dist-packages/optunity/solvers/ParticleSwarm.py in evaluate(d)
257 @functools.wraps(f)
258 def evaluate(d):
--> 259 return f(**d)
260
261 if maximize:
/usr/local/lib/python3.8/dist-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
/usr/local/lib/python3.8/dist-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
/usr/local/lib/python3.8/dist-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
/usr/local/lib/python3.8/dist-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
/usr/local/lib/python3.8/dist-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
/usr/local/lib/python3.8/dist-packages/optunity/cross_validation.py in call(self, *args, **kwargs)
402 kwargs['y_test'] = select(self.y, rows_test)
403 scores.append(self.f(**kwargs))
--> 404 return self.reduce(scores)
405
406 def getattr(self, name):
/usr/local/lib/python3.8/dist-packages/optunity/cross_validation.py in mean(x)
235
236 def mean(x):
--> 237 return float(sum(x)) / len(x)
238
239 def mean_and_list(x):
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
`