Issue
When I try to run this code I get following error.
IndentationError: unindent does not match any outer indentation level
It seems strange to me because I think this code worked before. the error appears with parentheses in 18 lines. it also seems that everything is OK with parentheses, just like spaces
%time
# This can take some time…
min_mae = float("Inf")
best_params = None
for eta in [.3, .2, .1, .05, .01, .005]:
print("CV with eta={}".format(eta))
# We update our parameters
params['eta'] = eta
# Run and time CV
%time cv_results = xgb.cv(
params,
dtrain,
num_boost_round=num_boost_round,
seed=42,
nfold=5,
metrics=['mae'],
early_stopping_rounds=10
)
# Update best score
mean_mae = cv_results['test-mae-mean'].min()
boost_rounds = cv_results['test-mae-mean'].argmin()
print("\tMAE {} for {} rounds\n".format(mean_mae, boost_rounds))
if mean_mae < min_mae:
min_mae = mean_mae
best_params = eta
print("Best params: {}, MAE: {}".format(best_params, min_mae))
Solution
The %time
line magic doesn't work like that with split lines. You either have to write your expression on a single line or add an explicit \
at the end of each line to escape the linebreak:
%time cv_results = xgb.cv(\
params, \
dtrain, \
num_boost_round=num_boost_round, \
seed=42, \
nfold=5, \
metrics=['mae'], \
early_stopping_rounds=10 \
)
Also, assuming your first line is meant to measure the execution time of the full code, you need to use the cell magic %%time
instead of %time
.
Answered By - jhansen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.