How to determine if my GBM model is overfitting? Below is a simplified example of a h2o gradient boosting machine model using R's iris dataset. The model is trained to predict sepal length. 

The example yields an r2 value of 0.93, which seems unrealistic. How can I assess if these are indeed realistic results or simply model overfitting?

library(datasets)
library(h2o)

# Get the iris dataset
df &lt;- iris

# Convert to h2o
df.hex &lt;- as.h2o(df)

# Initiate h2o
h2o.init()

# Train GBM model
gbm_model &lt;- h2o.gbm(x = 2:5, y = 1, df.hex, 
                     ntrees=100, max_depth=4, learn_rate=0.1)

# Check Accuracy
perf_gbm &lt;- h2o.performance(gbm_model) 
rsq_gbm &lt;- h2o.r2(perf_gbm)


----------> 

&gt; rsq_gbm
[1] 0.9312635
The term overfitting means the model is learning relationships between attributes that only exist in this specific dataset and do not generalize to new, unseen data.
Just by looking at the model accuracy on the data that was used to train the model, you won't be able to detect if your model is or isn't overfitting. 

To see if you are overfitting, split your dataset into two separate sets:


a train set (used to train the model)
a test set (used to test the model accuracy) 


A 90% train, 10% test split is very common. Train your model on the train test and evaluate its performance both on the test and the train set. If the accuracy on the test set is much lower than the models accuracy on the train set, the model is overfitting. 

You can also use cross-validation (e.g. splitting the data into 10 sets of equal size, for each iteration use one as test and the others as train) to get a result that is less influenced by irregularities in your splits.