Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, metric, maximize, optimizer='greedy'):
self.metric = metric
self.X = None
self.y = None
def _func(*weights):
return self.metric(self.y, np.average(self.X, axis=0, weights=weights))
if isinstance(optimizer, str):
if optimizer.lower() == 'pso':
self.optimizer = mlopt.optimization.ParticleSwarmOptimizer(func=_func, maximize=maximize)
elif optimizer.lower() == 'greedy':
self.optimizer = mlopt.optimization.GreedyOptimizer(func=_func, maximize=maximize)
else:
if hasattr(optimizer, 'optimize'):
self.optimizer = optimizer
else:
raise AttributeError('Provided optimizer does not have a optimize method.')
def __init__(self, metric, maximize, optimizer='greedy'):
self.metric = metric
self.X = None
self.y = None
def _func(*weights):
return self.metric(self.y, np.average(self.X, axis=0, weights=weights))
if isinstance(optimizer, str):
if optimizer.lower() == 'pso':
self.optimizer = mlopt.optimization.ParticleSwarmOptimizer(func=_func, maximize=maximize)
elif optimizer.lower() == 'greedy':
self.optimizer = mlopt.optimization.GreedyOptimizer(func=_func, maximize=maximize)
else:
if hasattr(optimizer, 'optimize'):
self.optimizer = optimizer
else:
raise AttributeError('Provided optimizer does not have a optimize method.')