for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
from sklearn.datasets import load_iris
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import cross_val_score
from hyperactive import Hyperactive
from hyperactive.optimizers import ParticleSwarmOptimizer
data = load_iris()
X, y = data.data, data.target
def model(opt):
knr = KNeighborsClassifier(n_neighbors=opt["n_neighbors"])
scores = cross_val_score(knr, X, y, cv=5)
score = scores.mean()
return score
search_space = {
"n_neighbors": list(range(1, 100)),
}
optimizer = ParticleSwarmOptimizer(
inertia=0.4,
cognitive_weight=0.7,
social_weight=0.7,
temp_weight=0.3,
rand_rest_p=0.05,
)
hyper = Hyperactive()
hyper.add_search(model, search_space, optimizer=optimizer, n_iter=100)
hyper.run()