Hi! I can’t figure out what combination of keys i should use for constructing the param_d list (in fact i’m a bit lost in all the variables)…
loop through each tuple in the list of tuples
for val_tuple in combination_l_of_t: # complete this line
param_d = {}
# Enumerate each key in the original hyperparams dictionary
for i, k in hyperparam.items(): # complete this line
# add a key value pair to param_d for each value in val_tuple
param_d[k] =
I understand that this is the step when we want to transform the list of combinations of hyperparameters to a dictionary, but i can’t see what this for loop does…
You may also have another issue in the second for-loop with the iteration over the hyperparameters. Lets see how this runs as is. If it fails we can work out this potential other issue.
It seems i’ve overcome this issue now using enumerate (indeed i suspected it was the problem), but now i’m ruminating on the next section where i use the hyperparameters in the model:
# Enumerate each key in the original hyperparams dictionary
for i, k in enumerate(hyperparam.keys()): # complete this line
# add a key value pair to param_d for each value in val_tuple
param_d[k] = val_tuple[i]
# append the param_dict to the list of dictionaries
combination_l_of_d.append(param_d)
# For each hyperparam dictionary in the list of dictionaries:
for param_d in combination_l_of_d: # complete this line
# Set the model to the given hyperparams
estimator = clf(param_d)
# Train the model on the training features and labels
estimator.fit(X_train_hp,y_train_hp)
# Predict the risk of death using the validation features
preds = estimator.predict_proba(X_val_hp)
Geting “n_estimators must be an integer, got <class ‘dict’>”
Sorry for the long line of questions, it seems like the trickiest assignment in the specialization
This is the snippet where the double asterisk is explained:
Let’s say you want to tweak this model’s default parameters. You can pass a dictionary containing the values you specify to the classifier when you instantiate it. Notice that these must be passed as keyword arguments, or kwargs , which are created by using the ** prefix
Check this link out if you want to learn more about args and kwargs in Python:
Thanks, indeed i forgot it was explained in the lab,
but still the same error appears (after correcting to “estimator = clf(**param_d)”),
“n_estimators must be an integer”
Got it!
Wrote concordance_index(y_val_hp,preds), where i needed to add preds[:,1], also,
in the ‘if’ statement “estimator_score>best_estimator” confused the estimator with the best_score.