I'm a beginner in this area so maybe I'm doing something wrong here. I'm using RandomForest for a regression model and wanted to see if my model is overfitting. Here is what I did:
EDIT:
I use GridSearchCV for hyperparameter tuning:
rf = RandomForestRegressor(random_state=0)
rf_params = {'n_estimators': [100, 500, 1000], 'max_depth': [3, 6, 9, None],
'min_samples_leaf': [2, 5, 10], 'max_features':['auto', 'sqrt']}
gs_rf = GridSearchCV(rf, rf_params, scoring = 'neg_mean_absolute_error', cv = 10)
gs_rf.fit(x_train, y_train.values.ravel())
b = gs_rf.best_params_
Then I create a RandomForestRegressor with those parameters:
RF = RandomForestRegressor(n_estimators=b['n_estimators'], max_depth=b['max_depth'], min_samples_leaf=b['min_samples_leaf'], max_features=b['max_features'], random_state=0)
Then I fit the model using the train dataset:
model = RF.fit(x_train, y_train.values.ravel())
Then I predict with the test dataset:
y_pred = model.predict(x_test)
Then I did the exact same with x_train instead of x_test:
y_pred = model.predict(x_train)
Here are the results that I achieve:
Test Data:
MAE: 15.11
MAPE: 26.98%
Train Data:
MAE: 6.17
MAPE: 10.97%
As you can see there is a pretty significant difference. Do I have a big problem with overfitting or am I doing something wrong when using x_train to predict?
Any help is much appreciated!