【发布时间】:2019-01-17 06:26:16
【问题描述】:
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.
【问题讨论】:
-
请分享代码。猜猜,你使用的是
predict函数而不使用fit。
标签: python scikit-learn random-forest