title: cross validation + decision trees in sklearn
body: <p>Attempting to create a decision tree with cross validation using sklearn and panads.</p>
  
  <p>My question is in the code below, the cross validation splits the data, which i then use for both training and testing.  I will be attempting to find the best depth of the tree by recreating it n times with different max depths set.  In using cross validation should i instead be using k folds CV and if so how would I use that within the code I have?</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  from sklearn import tree
  from sklearn import cross_validation
  
  features = ["fLength", "fWidth", "fSize", "fConc", "fConc1", "fAsym", "fM3Long", "fM3Trans", "fAlpha", "fDist", "class"]
  
  df = pd.read_csv('magic04.data',header=None,names=features)
  
  df['class'] = df['class'].map({'g':0,'h':1})
  
  x = df[features[:-1]]
  y = df['class']
  
  x_train,x_test,y_train,y_test = cross_validation.train_test_split(x,y,test_size=0.4,random_state=0)
  
  depth = []
  for i in range(3,20):
      clf = tree.DecisionTreeClassifier(max_depth=i)
      clf = clf.fit(x_train,y_train)
      depth.append((i,clf.score(x_test,y_test)))
  print depth
  </code></pre>
  
  <p>here is a link to the data that i am using in case that helps anyone.  <a href="https://archive.ics.uci.edu/ml/datasets/MAGIC+Gamma+Telescope" rel="noreferrer">https://archive.ics.uci.edu/ml/datasets/MAGIC+Gamma+Telescope</a></p>