def _get_best(self, results, history_results):
// type: (Dict, Dict) -> Estimator
Select the best estimator from the set of estimators.
best_model_id = first(results.info)
key = operator.itemgetter("model_id")
best_index = -1
// history_results is sorted by (model_id, partial_fit_calls)
// best is the model_id with the highest partial fit calls
for k, v in itertools.groupby(history_results, key=key):
v = list(v)
best_index += len(v)
if k == best_model_id:
break
return results.models[best_model_id], best_index
def _process_results(self, results):
Called with the output of `fit` immediately after it finishes.
After Change
// Could use max(scores, key=score.get), but what if score is repeated?
// Happens in the test case a lot
model_ids = list(scores.keys())
scores = [scores[k] for k in model_ids]
model_idx = np.argmax(scores)
best_model_id = model_ids[model_idx]
best_est = results.models[best_model_id]
idx = cv_results["model_id"] == best_model_id
assert idx.sum() == 1
best_idx = np.argmax(idx)