I have the following snippet I've written for a nested cross validation loop, but I'm confused how I would incorporate sequentialFeatureSelector into the mix as it has it's own CV statement. I'm thinking I need to do something similar to the references of "space = dict()" in https://machinelearningmastery.com/nested-cross-validation-for-machine-learning-with-python/ or better yet, how would I use it with nested_cv
# configure the cross-validation procedure
outer_k = 10
inner_k = 10
random_st = sample(list(np.arange(0,10,1)),1)[0]
#print(random_st)
cv_inner = KFold(n_splits=inner_k, shuffle=True, random_state=random_st)
cv_outer = KFold(n_splits=outer_k, shuffle=True, random_state=random_st+1)
outer_results = []
for outer_train_ix, outer_test_ix in cv_outer.split(X.index):
inner_results = []
for inner_train_ix, inner_test_ix in cv_outer.split(outer_train_ix):
print("inner_train_ix", inner_train_ix)
print("inner_test_ix",inner_test_ix)
#inner_results.append(inner_errors)
#best_model parms selected from the loop above
#best_model fitted to outer_train_ix, and out of sample errors are derived from outer_test_ix
print("outer_train_ix",outer_train_ix)
print("outer_test_ix",outer_test_ix)
#outer_results.append(outer_errors)
#model that performed best on the outer (out of sample) forecasts is selected
I believe I figured it out. I was misunderstanding that the model is SFS and the features are not to be mixed up with the parameter's. Nested CV would be used for comparing models with each other and then picking the best model. Therefore since there is only 1 model. I'm simply deriving it's nested CV error score.
https://gist.github.com/thistleknot/3a46e8a9cba8067ea7061828dbe31e8d