cross_val_score函数的参数scoring 求MSE
时间: 2024-05-02 16:17:49 浏览: 103
使用sklearn的cross_val_score进行交叉验证实例
可以使用scoring='neg_mean_squared_error'来求MSE,因为neg_mean_squared_error返回的是负的MSE,所以需要将结果取反,即将返回的值乘以-1。使用如下代码:
```python
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_boston
boston = load_boston()
X = boston.data
y = boston.target
lr = LinearRegression()
mse_scores = cross_val_score(lr, X, y, scoring='neg_mean_squared_error')
mse_scores = -mse_scores
print(mse_scores)
```
输出结果为:
```
[ 12.46171222 26.04898699 33.07413798 80.76237112 33.31360656]
```
阅读全文