<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p></p>
<div>Dear scikit experts,</div>
<div><br>
</div>
<div>I'm struggling with the implementation of a nested cross validation.</div>
<div><br>
</div>
<div>My data: I have 26 subjects (13 per class) x 6670 features. I used a feature reduction algorithm (you may have heard about Boruta) to reduce the dimensionality of my data. Problems start now: I defined LOSO as outer partitioning schema. Therefore, for
 each of the 26 cv folds I used 24 subjects for feature reduction. This lead to a different number of features in each cv fold. Now, for each cv fold I would like to use the same 24 subjects for hyperparameter optimization (SVM with rbf kernel).</div>
<div><br>
</div>
<div>This is what I did:</div>
<div><br>
</div>
<div><i>cv = list(LeaveOneout(len(y))) # in y I stored the labels</i></div>
<div><i><br>
</i></div>
<div><i>inner_train = [None] * len(y)</i></div>
<div><i><br>
</i></div>
<div><i>inner_test =  [None] * len(y)</i></div>
<div><i><br>
</i></div>
<div><i>ii = 0</i></div>
<div><i><br>
</i></div>
<div><i>while ii < len(y):</i></div>
<div><i>    cv = list(LeaveOneOut(len(y))) </i></div>
<div><i>    a = cv[ii][0]</i></div>
<div><i>    a = a[:-1]</i></div>
<div><i>    inner_train[ii] = a</i></div>
<div><i><br>
</i></div>
<div><i>    b = cv[ii][0]</i></div>
<div><i>    b = np.array(b[((len(cv[0][0]))-1)])</i></div>
<div><i>    inner_test[ii]=b</i></div>
<div><i><br>
</i></div>
<div><i>    ii = ii + 1</i></div>
<div><i><br>
</i></div>
<div><i>custom_cv = zip(inner_train,inner_test) # inner cv</i></div>
<div><i><br>
</i></div>
<div><i><br>
</i></div>
<div><i>pipe_logistic = Pipeline([('scl', StandardScaler()),('clf', SVC(kernel="rbf"))])</i></div>
<div><i><br>
</i></div>
<div><i>parameters = [{'clf__C':  np.logspace(-2, 10, 13), 'clf__gamma':np.logspace(-9, 3, 13)}]</i></div>
<div><i><br>
</i></div>
<div><i><br>
</i></div>
<div><i><br>
</i></div>
<div><i>scores = [None] * (len(y)) </i></div>
<div><i><br>
</i></div>
<div><i>ii = 0</i></div>
<div><i><br>
</i></div>
<div><i>while ii < len(scores):</i></div>
<div><i><br>
</i></div>
<div><i>    a = data[ii][0] # data for train</i></div>
<div><i>    b = data[ii][1] # data for test</i></div>
<div><i>    c = np.concatenate((a,b)) # shape: number of subjects * number of features</i></div>
<div><i>    d = cv[ii][0] # labels for train</i></div>
<div><i>    e = cv[ii][1] # label for test</i></div>
<div><i>    f = np.concatenate((d,e))</i></div>
<div><i><br>
</i></div>
<div><i>    grid_search = GridSearchCV(estimator=pipe_logistic, param_grid=parameters, verbose=1, scoring='accuracy', cv= zip(([custom_cv[ii][0]]), ([custom_cv[ii][1]])))</i></div>
<div><i><br>
</i></div>
<div><i>    scores[ii] = cross_validation.cross_val_score(grid_search, c, y[f], scoring='accuracy', cv = zip(([cv[ii][0]]), ([cv[ii][1]])))</i></div>
<div><i><br>
</i></div>
<div><i>    ii = ii + 1</i></div>
<div>    </div>
<div>    </div>
<div>    </div>
<div>However, I got the following error message: index 25 is out of bounds for size 25</div>
<div><br>
</div>
<div>Would it be so bad if I do not perform a nested LOSO but I use the default setting for hyperparameter optimization?</div>
<div><br>
</div>
<div>Any help would be really appreciated</div>
<br>
<p></p>
</div>
</body>
</html>