scikit-learn/scikit-learn — pull request #2036 by mbatchkarov (2013-06-05 19:02:42+00:00)
Title: Added unique identifier to cloned estimators in cross_validation.cross_val_score()

Currently all estimators used in cross-validation are identical, because they are clones of a single "proto-estimator". I added an extra attribute to each of the clones, so that they are aware that they are clone and are uniquely identifiable.

Motivation:
I often find I need to write some debugging information to disk, and I want the output of each cross-validation fold to go to a separate file. The example below illustrates a possible use of the newly added ```cv_number``` attribute:
```python
class MyVectorizer(CountVectorizer):
def fit_transform(self, X, y):
if hasattr(self, 'cv_id'):
with open('debug_file_%d'%self.cv_number) as outfile:
outfile.write('Estimator %d fitting %d data points'%(self.cv_number, len(y))
return super(MyVectorizer, self).fit_transform(X, y)
```