I have a prediction code that runs RandomForestRegressor
and RandomForestClassifier
.
I call the functions 9 times each respectively and it is optimised by GridSearchCV
.
The first time it ran, it took around 2 Hrs, 20 mins to run and almost after every run cycle, the duration has been steadily increasing and it took 3Hrs 45 Mins today. I have run the code 20 times so far and every time, the duration increases slightly while there is no change in underlying training data and the size of testing data.
While I take care to clear cache every time I run the code, I am unsure why it takes an increased amount of time to run the same.
Well, the general question would be "How can I optimise a code?" But, I guess this would be specifically SkLearn? The rest of the codes dont observe the same behaviour and is specific to the prediction code.
For RandomForestRegressor
:
param_grid_rf = {
'max_features': ['auto', 'sqrt', 'log2'],
# 'criterion': ['mse', 'mae'] #mae takes forever to run and mse is default
}
rf = RandomForestRegressor()
rf = GridSearchCV(estimator=rf, param_grid=param_grid_rf, n_jobs=-2)
For RandomForestClassifier
:
param_grid_rc = {
'max_features': ['auto', 'sqrt', 'log2'],
'criterion': ['gini', 'entropy']
}
rc = RandomForestClassifier()
rc = GridSearchCV(estimator=rc, param_grid=param_grid_rc, n_jobs=-2)
I cannot post the code in its entirely hence this open ended question.
I am using Windows 10
and Pycharm
as my environment.