<div dir="ltr">Hi!<div><br></div><div>It looks like you are using the old `sklearn.cross_validation`'s LeaveOneLabelOut cross-validator. It has been deprecated since v0.18.</div><div><br></div><div>Use the `LeaveOneLabelOut` from `sklearn.model_selection`, that should fix your issue I think (thought I have not looked into your code in detail).</div><div><br></div><div>HTH!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 4, 2016 at 9:12 PM, Ludovico Coletta <span dir="ltr"><<a href="mailto:ludo25_90@hotmail.com" target="_blank">ludo25_90@hotmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div id="m_7309286880399812375divtagdefaultwrapper" 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)<wbr>])</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_<wbr>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_<wbr>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>
</div>

<br>______________________________<wbr>_________________<br>
scikit-learn mailing list<br>
<a href="mailto:scikit-learn@python.org">scikit-learn@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scikit-learn</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div style="font-size:small">Raghav RV</div><div style="font-size:small"><a href="https://github.com/raghavrv" style="color:rgb(17,85,204)" target="_blank">https://github.com/raghavrv</a></div><div><br></div></div></div>
</div>