title: Why Decision Tree code written in python predicts differently than the code written in R?
body: <p>I am working with load_iris data set from sklearn in python and R(it's just called iris in R).</p>
  
  <p>I built the model in both language using "gini" index and in both languages I am able to test the model properly when the test data is taken directly from the iris data set.</p>
  
  <p>However if I give a new data set as a test input, for the same python and R puts it into different categories.</p>
  
  <p>I'm not sure what am I missing here or doing wrong, so any guidance will be very much appreciated.</p>
  
  <p>Code mentioned below:
  Python 2.7:</p>
  
  <pre><code>from sklearn.datasets import load_iris
  from sklearn import tree
  iris = load_iris()
  model = tree.DecisionTreeClassifier(criterion='gini')
  model.fit(iris.data, iris.target)
  model.score(iris.data, iris.target)
  print iris.data[49],model.predict([iris.data[49]])
  print iris.data[99],model.predict([iris.data[99]])
  print iris.data[100],model.predict([iris.data[100]])
  print iris.data[149],model.predict([iris.data[149]])
  print [6.3,2.8,6,1.3],model.predict([[6.3,2.8,6,1.3]])
  </code></pre>
  
  <p>R-Rstudio running 3.3.2 32 bit:</p>
  
  <pre><code>library(rpart)
  iris&lt;- iris
  x_train = iris[c('Sepal.Length','Sepal.Width','Petal.Length','Petal.Width')]
  y_train = as.matrix(cbind(iris['Species']))
  x &lt;- cbind(x_train,y_train)
  fit &lt;- rpart(y_train ~ ., data = x_train,method="class",parms = list(split = "gini"))
  summary(fit)
  x_test = x[149,]
  x_test[,1]=6.3
  x_test[,2]=2.8
  x_test[,3]=6
  x_test[,4]=1.3
  predicted1= predict(fit,x[49,]) # same as python result
  predicted2= predict(fit,x[100,]) # same as python result 
  predicted3= predict(fit,x[101,]) # same as python result
  predicted4= predict(fit,x[149,]) # same as python result
  predicted5= predict(fit,x_test) ## this value does not match with pythons result
  </code></pre>
  
  <p>My python output is :</p>
  
  <pre><code>[ 5.   3.3  1.4  0.2] [0]
  [ 5.7  2.8  4.1  1.3] [1]
  [ 6.3  3.3  6.   2.5] [2]
  [ 5.9  3.   5.1  1.8] [2]
  [6.3, 2.8, 6, 1.3] [2] -----&gt; this means it's putting the test data into virginica bucket
  </code></pre>
  
  <p>and R output is:</p>
  
  <pre><code>&gt; predicted1
     setosa versicolor virginica
  49      1          0         0
  &gt; predicted2
      setosa versicolor  virginica
  100      0  0.9074074 0.09259259
  &gt; predicted3
      setosa versicolor virginica
  101      0 0.02173913 0.9782609
  &gt; predicted4
      setosa versicolor virginica
  149      0 0.02173913 0.9782609
  &gt; predicted5
      setosa versicolor  virginica
  149      0  0.9074074 0.09259259 --&gt; this means it's putting the test data into versicolor bucket
  </code></pre>
  
  <p>Please help. Thank you.</p>