# Random Forest Variable Importance in R and Python

I am new to random forests and have tried to implement it in both R and Python. I was following a paper that compared the two and followed their exact steps, however, when I plot the variable importance, the Gini index scaling is different and the variables seem to be different as well. Can someone please explain why the scaling is different, and which software I should base my results upon? If my main concern is variable importance, should I run the random forest through my whole data set, or is it still wise to split my data into a train/test set and retrieve the important variables from the training set? I tried implementing rf using the whole data set just to see if that would give me the same results and I still get different results.

R code

rf <- randomForest(Cell~., data = val, importance = TRUE)


Python code

rnd_clf = RandomForestClassifier(n_estimators=500,oob_score=True,criterion='gini')
bc_rf = rnd_clf.fit(dat1, bc_Y)


Finally yes, the whole dataset should be used when training our final model. That way we can get the maximum insights from our available data. Notice that this concerns "using the model" to production (or in this case reporting the model weights), rather than "comparing the model" against another one (in which case the CV (or resampling) is more relevant). In case you are unaware of it you might find the R package randomForestExplainer, it offers some excellent visualisation functions for RF in terms of variable importances. I strongly suspect similar packages exist for Python but I have not come across them personally.