【发布时间】:2021-01-07 07:12:19
【问题描述】:
我正在尝试使用 RandomForestRegressor 预测未来的冠状病毒病例数,但是当我尝试执行它时它给了我这种错误:
ValueError Traceback (most recent call last)
<ipython-input-181-c9a9a8208098> in <module>()
1 test_data = np.arange(260, 367).reshape(-1, 1)
----> 2 rf_regressor_fit_future = rf_regressor.fit(test_data, target)
3 forecast_rf_future = rf_regressor_fit_future.predict(test_data)
10 frames
/usr/local/lib/python3.6/dist-packages/sklearn/tree/_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
263 if len(y) != n_samples:
264 raise ValueError("Number of labels=%d does not match "
--> 265 "number of samples=%d" % (len(y), n_samples))
266 if not 0 <= self.min_weight_fraction_leaf <= 0.5:
267 raise ValueError("min_weight_fraction_leaf must in [0, 0.5]")
ValueError: Number of labels=259 does not match number of samples=107
这是我使用示例创建未来日子和预测的代码:
test_data = np.arange(260, 367).reshape(-1, 1)
rf_regressor_fit_future = rf_regressor.fit(test_data, target)
forecast_rf_future = rf_regressor_fit_future.predict(test_data)
数据集只有 259 天和样本,预测实际数据运行良好。但我在未来的日子里遇到了问题。我应该怎么做才能通过匹配样本数量来解决这个错误?任何建议都非常感谢。
【问题讨论】:
标签: python machine-learning data-science random-forest