Product Demand Forecasting issues with Random Forest regression

Hi,
I am using the following code for doing the Random Forest regression:

Random Forest Regressor

from sklearn.ensemble import RandomForestRegressor

rf = RandomForestRegressor(n_estimators = 10, random_state=42)
rf.fit(PDemand_prepared, PDemand_labels)

Model Fitting

PDemand_predictions = rf.predict(PDemand_prepared)


Getting error message -->


IndexError Traceback (most recent call last)
in
----> 1 PDemand_predictions = rf.predict(PDemand_prepared)

/usr/local/anaconda/lib/python3.6/site-packages/sklearn/ensemble/_forest.py in predict(self, X)
764 check_is_fitted(self)
765 # Check data
–> 766 X = self._validate_X_predict(X)
767
768 # Assign chunk of trees to jobs

/usr/local/anaconda/lib/python3.6/site-packages/sklearn/ensemble/_forest.py in validate_X_predict(self, X)
410 check_is_fitted(self)
411
–> 412 return self.estimators
[0]._validate_X_predict(X, check_input=True)
413
414 @property

IndexError: list index out of range


Getting the same error “IndexError: list index out of range” while calculating RMSE of RF model

Calculate RMSE in Random Forest model

import numpy as np
from sklearn import metrics

PDemand_predictions = rf.predict(PDemand_prepared)

print(‘Root Mean Squared Error:’, np.sqrt(metrics.mean_squared_error(PDemand_labels, PDemand_predictions)))



IndexError Traceback (most recent call last)
in
3 from sklearn import metrics
4
----> 5 PDemand_predictions = rf.predict(PDemand_prepared)
6
7 print(‘Root Mean Squared Error:’, np.sqrt(metrics.mean_squared_error(PDemand_labels, PDemand_predictions)))

/usr/local/anaconda/lib/python3.6/site-packages/sklearn/ensemble/_forest.py in predict(self, X)
764 check_is_fitted(self)
765 # Check data
–> 766 X = self._validate_X_predict(X)
767
768 # Assign chunk of trees to jobs

/usr/local/anaconda/lib/python3.6/site-packages/sklearn/ensemble/_forest.py in validate_X_predict(self, X)
410 check_is_fitted(self)
411
–> 412 return self.estimators
[0]._validate_X_predict(X, check_input=True)
413
414 @property

IndexError: list index out of range


Please advise how to fix this?
Thanks