rmse, estimator.coef_[0][1][2][3], estimator.intercept_[0], estimator.intercept_[1], estimator.intercept_[2], IndexError: invalid index to scalar variable.
时间: 2023-08-18 22:23:32 浏览: 52
这个错误的原因是`estimator.intercept_`是一个一维数组,不能使用`[1]`和`[2]`这样的索引,而应该只使用`[0]`这个索引。你可以将代码中的`estimator.intercept_[1]`和`estimator.intercept_[2]`改为`estimator.intercept_[0]`,如下所示:
```python
title += "RMSE = {:.2f}, estimator.coef_ = {:.2f}%, {:.2f}%, {:.2f}%, {:.2f}%, estimator.intercept_ = {:.2f}%".format(rmse, estimator.coef_[0][1][2][3], estimator.intercept_[0], estimator.intercept_[0], estimator.intercept_[0])
```
这样就可以正确地将RMSE、回归系数和偏置系数等信息添加到图表的标题中了。
相关问题
rmse, estimator.coef_[0][1][2][3], estimator.intercept_[0], estimator.intercept_[0], estimator.intercept_[0], IndexError: invalid index to scalar variable.
这个错误的原因是`estimator.intercept_`是一个一维数组,不能使用`[1]`和`[2]`这样的索引,而应该只使用`[0]`这个索引。你可以将代码中的`estimator.intercept_[1]`和`estimator.intercept_[2]`都改为`estimator.intercept_[0]`,如下所示:
```python
title += "RMSE = {:.2f}, estimator.coef_ = {:.2f}%, {:.2f}%, {:.2f}%, {:.2f}%, estimator.intercept_ = {:.2f}%".format(rmse, estimator.coef_[0][1][2][3], estimator.intercept_[0], estimator.intercept_[0], estimator.intercept_[0], estimator.intercept_[0])
```
这样就可以正确地将RMSE、回归系数和偏置系数等信息添加到图表的标题中了。
title += "RMSE = {:.2f}, estimator.coef_ = {:.2f}%, {:.2f}%, {:.2f}%, {:.2f}%, estimator.intercept_ = {:.2f}%".format(rmse, estimator.coef_[0][1][2][3], estimator.intercept_[0]) IndexError: invalid index to scalar variable.
这个错误的原因是格式化字符串中的`{:.2f}%, {:.2f}%, {:.2f}%, {:.2f}%`位置有四个占位符,但是传入的参数只有一个(即`estimator.intercept_[0]`)。你需要将格式化字符串中的占位符个数和参数个数对应起来,如下所示:
```python
title += "RMSE = {:.2f}, estimator.coef_ = {:.2f}%, {:.2f}%, {:.2f}%, {:.2f}%, estimator.intercept_ = {:.2f}%".format(rmse, estimator.coef_[0][1][2][3], estimator.intercept_[0], estimator.intercept_[0], estimator.intercept_[0], estimator.intercept_[0])
```
这样就可以正确地将RMSE、回归系数和偏置系数等信息添加到图表的标题中了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)