You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cross validation module should allow the user to provide its own (X_train, X_test) generators #5915
The whole cross validation / parameter search relies on sample masks rather than train / test physical datasets. This is not convenient if we need for example to remove some features /sample from a sparse dataset to evaluate reconstruction. More flexibility would be possible if we were able to provide an iterator of (X_train, X_test) to GridSearchCV / cross_val_score.
I have been doing some hacks to be able to run recommender systems within sklearn. Cross validation implies taking a sparse matrix X(n_samples, n_features), with missing values, and to remove e.g. 20% of the features (different for each sample) for the training set, keeping them for the test test. Working with sparse matrix require specific construction of (X_test, X_train) for efficiency, so it would be great to be able to bypass automatic construction of these two matrices from provided splits. This is probably too early for it be useful for the end user, just writing it there to keep it in mind.
The way I finally went was to use OneHotEncoder, split data, and go back to CSR matrix. @rvraghav93 the problem with this approach is that we work with sparse matrix, for which such indexing breaks the sparse structure
I'd like to mention that the PredefinedSplit code currently is not well-suited for anomaly detection. This is because the abnormal set must not be trained on, but still must be used for validation. At the moment, it's only possible to make one fold (because each member of test_code can only be the member of one validation fold) but it is indeed possible to reuse the validation set.
@arthurmensch I recommend we close this issue. In particular because of "and to remove e.g. 20% of the features (different for each sample) for the training set, keeping them for the test test"
You want to treat each sample differently. That's not really what cross-validation iterators are for.
Also, which part of grid-search do you actually want to use?
Activity
raghavrv commentedon Nov 24, 2015
We can do that with
PredefinedSplitright?arthurmensch commentedon Nov 24, 2015
I have been doing some hacks to be able to run recommender systems within sklearn. Cross validation implies taking a sparse matrix
X(n_samples, n_features), with missing values, and to remove e.g.20%of the features (different for each sample) for the training set, keeping them for the test test. Working with sparse matrix require specific construction of(X_test, X_train)for efficiency, so it would be great to be able to bypass automatic construction of these two matrices from provided splits. This is probably too early for it be useful for the end user, just writing it there to keep it in mind.raghavrv commentedon Nov 25, 2015
Ah! You want cross validation with missing values... sounds interesting...
You can do something like...
And in the
train_indicesyou could specify you train matrix indexingSince internally
GridSearchCVtrains onX[train], you can specifytrain_indicesto be anything that is acceptable by numpy's slice notation...i.e
X[train_indices]will be the matrix with 20% missing values andX[test_indices]would be the full matrix...Is this what you had wanted?
raghavrv commentedon Dec 9, 2015
Could you confirm if I had understood your comment correctly?
amueller commentedon Dec 9, 2015
That's where the problem lies. Recommender systems don't really fit in the sklearn API ;)
arthurmensch commentedon Dec 11, 2015
The way I finally went was to use
OneHotEncoder, split data, and go back to CSR matrix. @rvraghav93 the problem with this approach is that we work with sparse matrix, for which such indexing breaks the sparse structurepunyidea commentedon Jul 21, 2016
I'd like to mention that the
PredefinedSplitcode currently is not well-suited for anomaly detection. This is because the abnormal set must not be trained on, but still must be used for validation. At the moment, it's only possible to make one fold (because each member of test_code can only be the member of one validation fold) but it is indeed possible to reuse the validation set.amueller commentedon Jul 27, 2016
@punyidea can you open a separate issue providing a more detailed explanation and maybe some code? What would a better interface look like?
amueller commentedon Jul 27, 2016
@arthurmensch I recommend we close this issue. In particular because of "and to remove e.g. 20% of the features (different for each sample) for the training set, keeping them for the test test"
You want to treat each sample differently. That's not really what cross-validation iterators are for.
Also, which part of grid-search do you actually want to use?
amueller commentedon Oct 27, 2016
closing as @arthurmensch didn't object ;)