the k-fold test can get result just by itself?
<p>My problem is when i comment the pipe_lr in the first line, I can still get accuracy score. It make me so confused, I think it should report an error why? It looks like it don't need the definition of the pipe_lr. This the relevant part. <a href="http://i.stack.imgur.com/l0xbB.png" rel="nofollow">enter image description here</a></p>

<pre><code>from sklearn.ensemble import ExtraTreesClassifier
from sklearn.feature_selection import SelectFromModel
import pandas as pd
import numpy as np
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import LabelEncoder
from sklearn.pipeline import Pipeline
from sklearn.tree import DecisionTreeClassifier
from sklearn.cross_validation import StratifiedKFold


pipe_lr=Pipeline([('normalization',mms),
                  ('feature_selection',feature_selection),
                  ('classification',DecisionTreeClassifier())])

"""
K-fold test
"""

kfold=StratifiedKFold(y=y_train,n_folds=10,random_state=1)
scores=[]
features=[]
for k,(train,test) in enumerate (kfold):
    pipe_lr.fit(X_train[train],y_train[train])
    score=pipe_lr.score(X_train[test],y_train[test])

    scores.append(score)
    print('Fold: %s, Class dist.: %s,Acc: %.3f' %(k+1,
            np.bincount(y_train[train]), score))
</code></pre>

<p>The short answer is <strong>no, it cannot</strong>. Your code will not run without <code>pipe_lr</code> line. The only reason for it to run without it is because you ran it in some peculiar environment, like ipython notebook, and previously you ran the same code <strong>with</strong> this line, thus it still persists in your memory in the same scope (thus second run still accesses the original <code>pipe_lr</code> object). Or you actually defined this variable somewhere else in your code (for example in the chunk which defines data, <code>mms</code> etc. which you removed from the question itself). There is no way for this code to work (or even run) without <code>pipe_lr</code> when <strong>correctly run</strong> in the clean environment. </p>

python machine-learning scikit-learn