<jupyter_start><jupyter_text>Format DataFrameBe advised, this dataset (SKLearn's Forest Cover Types) can take a little while to download...This is a multi-class classification task, in which the target is label-encoded.<jupyter_code>import pandas as pd
from sklearn.datasets import fetch_covtype

data = fetch_covtype(shuffle=True, random_state=32)
train_df = pd.DataFrame(data.data, columns=["x_{}".format(_) for _ in range(data.data.shape[1])])
train_df["y"] = data.target

print(train_df.shape)
train_df.head()<jupyter_output>(581012, 55)<jupyter_text>Set Up Environment<jupyter_code>from hyperparameter_hunter import Environment, CVExperiment
from sklearn.metrics import f1_score

env = Environment(
    train_dataset=train_df,
    results_path="HyperparameterHunterAssets",
    target_column="y",
    metrics=dict(f1=lambda y_true, y_pred: f1_score(y_true, y_pred, average="micro")),
    cv_type="StratifiedKFold",
    cv_params=dict(n_splits=5, random_state=32),
)<jupyter_output>Cross-Experiment Key:   'WQMO2i1RnEaE7cguWwpBywkh25UKTgtwR12Z0LqWIUM='<jupyter_text>Now that HyperparameterHunter has an active `Environment`, we can do two things: 1. Perform Experiments<jupyter_code>from lightgbm import LGBMClassifier

experiment = CVExperiment(
    model_initializer=LGBMClassifier,
    model_init_params=dict(boosting_type="gbdt", num_leaves=31, max_depth=-1, subsample=0.5),
    model_extra_params=dict(
        fit=dict(
            feature_name=train_df.columns.values[:-1].tolist(),
            categorical_feature=train_df.columns.values[11:-1].tolist(),
        ),
    ),
)<jupyter_output><15:06:35> Validated Environment:  'WQMO2i1RnEaE7cguWwpBywkh25UKTgtwR12Z0LqWIUM='
<15:06:35> Initialized Experiment: 'f2096258-17fd-47b4-a384-362a43cc8cbd'
<15:06:35> Hyperparameter Key:     '<KEY>
<15:06:35> 
<15:06:44> F0.0 AVG:   OOF(f1=0.83622)  |  Time Elapsed: 9.24039 s
<15:06:54> F0.1 AVG:   OOF(f1=0.83796)  |  Time Elapsed: 9.17901 s
<15:07:03> F0.2 AVG:   OOF(f1=0.83635)  |  Time Elapsed: 9.43469 s
<15:07:12> F0.3 AVG:   OOF(f1=0.83682)  |  Time Elapsed: 9.32817 s
<15:07:22> F0.4 AVG:   OOF(f1=0.83370)  |  Time Elapsed: 9.22297 s
<15:07:22> 
<15:07:22> FINAL:    OOF(f1=0.83621)  |  Time Elapsed: 46.77216 s
<15:07:22> 
<15:07:22> Saving results for Experiment: 'f2096258-17fd-47b4-a384-362a43cc8cbd'<jupyter_text>2. Hyperparameter Optimization<jupyter_code>from hyperparameter_hunter import RandomForestOptimization, Real, Integer, Categorical

optimizer = RandomForestOptimization(iterations=10, random_state=32)

optimizer.set_experiment_guidelines(
    model_initializer=LGBMClassifier,
    model_init_params=dict(
        boosting_type=Categorical(["gbdt", "dart"]),
        num_leaves=Integer(10, 40),
        max_depth=-1,
        subsample=Real(0.3, 0.7),
    ),
    model_extra_params=dict(
        fit=dict(
            feature_name=train_df.columns.values[:-1].tolist(),
            categorical_feature=train_df.columns.values[11:-1].tolist(),
        ),
    ),
)

optimizer.go()<jupyter_output>Validated Environment with key: "<KEY>
[31mSaved Result Files[0m
[31m_______________________________________________________________________________________[0m
 Step |       ID |   Time |      Value |   boosting_type |   num_leaves |   subsample | 
Experiments matching cross-experiment key/algorithm: 1
Experiments fitting in the given space: 1
Experiments matching current guidelines: 1
    0 | f2096258 | 00m00s | [35m   0.83621[0m | [32m           gbdt[0m | [32m          31[0m | [32m     0.5000[0m | 
[31mHyperparameter Optimization[0m
[31m_______________________________________________________________________________________[0m
 Step |       ID |   Time |      Value |   boosting_type |   num_leaves |   subsample | 
    1 | 00708066 | 01m23s |    0.76716 |            dart |           15 |      0.4684 | 
    2 | dd0307d2 | 00m52s |    0.83191 |            gbdt |           29 |      0.5947 | 
    3 | e3b29434 | 01m20s |    0.76080 | [...]
{'fraction_non_alphanumeric': 0.11985957873620863, 'fraction_numerical': 0.09729187562688064, 'mean_word_length': 4.2007822685788785, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '313952', 'license': 'MIT', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1488, 'n_words': 262, 'path': 'examples/lightgbm_examples/classification.ipynb', 'repo_name': 'mdjabc/hyperparameter_hunter', 'size': '4068'}