scikit-learn/scikit-learn — pull request #1787 by jnothman (2013-03-18 03:28:38+00:00)
Title: ENH extensible parameter search results using structured arrays

`GridSearch` and friends need to be able to return more fields in their results (e.g. #1742, [composite score](http://sourceforge.net/mailarchive/forum.php?thread_name=513C6BDD.8020001%40ais.uni-bonn.de&forum_name=scikit-learn-general)).

More generally, the conceivable results from a parameter search can be classified into:
# per-parameter setting, per-fold
# per-parameter setting
# per-search

Currently, `cv_scores_`/`grid_scores_` stores: the parameters (1.), the mean test score (1.), the test scores for each fold (2.); `best_params_`, `best_score_` and `best_estimator_` are per search (3.) results. However `best_params_` and `best_score_` are redundantly available in `grid_scores_` as long as the index of the best parameters is known.

Hence this patch changes the output of a parameter search to be (attribute names are open for debate!):
* `grid_results_` (1.) a structured array (a numpy array with named fields) with one record per set of parameters
* `fold_results_` (2.) a structured array with one record per fold per set of parameters
* `best_index_` (3.)
* `best_estimator_` if `refit==True` (3.)

The structured arrays can be indexed by field name to produce an array of values, or alternatively can be indexed as an array to produce a single record, akin to the `namedtuple`s introduced in 0c94b55 (not in 0.13.1). In any case it allows numpy vectorised operations, as used here when calculating the mean score for each parameter setting (in `_aggregate_scores`).

Given this data, the legacy `grid_scores_` (already deprecated), `best_params_` and `best_scores_` are calculated as properties.

This approach is extensible to new fields, in particular new fields within `fold_results_` records, which are compiled from dicts returned from `fit_fold` (formerly `fit_grid_point`).

This PR is cut back from #1768; there you can see the benefit of this approach exemplified to store training scores, training and test times, and precision and recall together with F-score.