cross_val_score函数的参数scoring 求RMSE
时间: 2024-05-15 15:19:39 浏览: 176
使用sklearn的cross_val_score进行交叉验证实例
cross_val_score函数的参数scoring可以设置为'mean_squared_error',然后用-mean_squared_error来得到均方根误差(RMSE)的值,即:
```python
from sklearn.model_selection import cross_val_score
from sklearn.metrics import mean_squared_error
import numpy as np
# 假设模型为model,数据为X和y
scores = cross_val_score(model, X, y, cv=5, scoring='mean_squared_error')
rmse_scores = np.sqrt(-scores)
print("RMSE:", rmse_scores.mean())
```
其中,np.sqrt(-scores)是将均方误差(MSE)转换为均方根误差(RMSE)的公式。
阅读全文