<jupyter_start><jupyter_text><jupyter_code>from sklearn.model_selection import cross_val_score
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.tree import DecisionTreeRegressor

from sklearn.datasets import load_boston
from hyperactive import Hyperactive<jupyter_output><empty_output><jupyter_text>First Chapter ...............<jupyter_code>data = load_boston()
X, y = data.data, data.target


def knr_model(opt):
    knr = KNeighborsRegressor(
        n_neighbors=opt["n_neighbors"],
        leaf_size=opt["leaf_size"],
    )
    scores = cross_val_score(knr, X, y)

    return scores.mean()


search_space_knr = {
    "n_neighbors": list(range(3, 25)),
    "leaf_size": list(range(5, 100)),
}
hyper_knr_0 = Hyperactive()
hyper_knr_0.add_search(knr_model, search_space_knr, n_iter=300)
hyper_knr_0.run()
def knr_model(opt):
    knr = KNeighborsRegressor(
        n_neighbors=opt["n_neighbors"],
        leaf_size=opt["leaf_size"],
    )
    scores = cross_val_score(knr, X, y)

    return scores.mean()


search_space_knr = {
    "n_neighbors": list(range(3, 25)),
    "leaf_size": list(range(5, 100)),
}
from hyperactive import EvolutionStrategyOptimizer

optimizer = EvolutionStrategyOptimizer()

hyper_knr_1 = Hyperactive()
hyper_knr_1.add_search(knr_model, search_space_knr, n_iter=300, optimizer=optimizer)
hyper_knr_1.run()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11818181818181818, 'fraction_numerical': 0.01818181818181818, 'mean_word_length': 5.388392857142857, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '653467', 'license': 'MIT', 'n_tokens_mistral': 570, 'n_tokens_neox': 529, 'n_words': 88, 'path': 'notebooks/Hyperactive Machine Learning Tutorial.ipynb', 'repo_name': 'SimonBlanke/hyperactive-tutorial', 'size': '1430'}