Desc: 在给定数据集上计算误差。 Args: dataSet -- 输入数据集 Returns: 调用 linearSolve 函数,返回 yHat 和 Y 之间的平方误差。
(dataSet)
| 264 | |
| 265 | # 计算线性模型的误差值 |
| 266 | def modelErr(dataSet): |
| 267 | """ |
| 268 | Desc: |
| 269 | 在给定数据集上计算误差。 |
| 270 | Args: |
| 271 | dataSet -- 输入数据集 |
| 272 | Returns: |
| 273 | 调用 linearSolve 函数,返回 yHat 和 Y 之间的平方误差。 |
| 274 | """ |
| 275 | ws, X, Y = linearSolve(dataSet) |
| 276 | yHat = X * ws |
| 277 | # print corrcoef(yHat, Y, rowvar=0) |
| 278 | return sum(power(Y - yHat, 2)) |
| 279 | |
| 280 | |
| 281 | # helper function used in two places |
nothing calls this directly
no test coverage detected