Python新手。我正在尝试运行具有5个功能和一个标签的简单随机森林模型,但是当我运行RandomForestRegressor时,出现一个NotFittedError(以下),我不理解。
任何帮助表示赞赏...
---------------------------------------------------------------------------
NotFittedError Traceback (most recent call last)
<ipython-input-86-b670604a6f52> in <module>()
----> 1 predictions = rf.predict(train_features)
/anaconda3/lib/python3.6/site-packages/sklearn/ensemble/forest.py in predict(self, X)
677 The predicted values.
678 """
--> 679 check_is_fitted(self, 'estimators_')
680 # Check data
681 X = self._validate_X_predict(X)
/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py in check_is_fitted(estimator, attributes, msg, all_or_any)
766
767 if not all_or_any([hasattr(estimator, attr) for attr in attributes]):
--> 768 raise NotFittedError(msg % {'name': type(estimator).__name__})
769
770
NotFittedError: This RandomForestRegressor instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.
答案 0 :(得分:0)
首先训练fit
的{{1}}数据,然后训练model
predict