上QQ阅读APP看书,第一时间看更新
Cross-validation
And now we come to the final part—in order to compare models, we would like to cross-validate the model. We've already set aside a portion of the data. Now, we will have to test the model on the data that was set aside, and compute a score.
The score we'll be using is a Root Mean Square Error. It's used because it's simple and straightforward to understand:
// VERY simple cross validation
var MSE float64
for i, row := range testingSet {
pred, err := r.Predict(row)
mHandleErr(err)
correct := testingYs[i]
eStar := correct - pred
e2 := eStar * eStar
MSE += e2
}
MSE /= float64(len(testingSet))
fmt.Printf("RMSE: %v\n", math.Sqrt(MSE))
With this, now we're really ready to run the regression analysis.