Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Conditional parameter spec for hyperparameter tuning for logistic regression

How to configure conditonalparameterspec for the below code where, when penalty is l2 solver should be 'sag' and when penalty is 'l1', solver should be 'saga'.
 
from google.cloud.aiplatform import hyperparameter_tuning as hpt

worker_pool_specs = [
        {
            "machine_spec": {
                "machine_type": "n1-standard-4",
                "accelerator_type": "NVIDIA_TESLA_K80",
                "accelerator_count": 1,
            },
            "replica_count": 1,
            "container_spec": {
                "image_uri": container_image_uri,
                "command": [],
                "args": [],
            },
        }
    ]

custom_job = aiplatform.CustomJob(
    display_name='my_job',
    worker_pool_specs=worker_pool_specs,
    labels={'my_key': 'my_value'},
)


hp_job = aiplatform.HyperparameterTuningJob(
    display_name='hp-test',
    custom_job=job,
    metric_spec={
        'loss': 'minimize',
    },
    parameter_spec={
        'C': hpt.DoubleParameterSpec(min=0.001, max=0.1, scale='log'),
        'max_iter': hpt.IntegerParameterSpec(min=4, max=128, scale='linear'),
        'penalty': hpt.CategoricalParameterSpec(values=['l1', 'l2']),
        'solver': hpt.CategoricalParameterSpec(values=['sag', 'saga'])
    },
    max_trial_count=128,
    parallel_trial_count=8,
    labels={'my_key': 'my_value'},
    )

hp_job.run()

print(hp_job.trials)

I have looked into documentations and have tried asking help from GPTs but am not able to figure it out. Could you guys help?

4 REPLIES 4