Practical Predictive Analytics
上QQ阅读APP看书,第一时间看更新

The predict function

To predict the value for all of the values we will use a function called predict(). This function reads each input (independent) variable and then predicts a target (dependent) variable based on the linear regression equation. In the code we have assigned the output of this function to a new object named prediction.

Switch over to the console area, and type prediction, then Enter,  to see the predicted values for the 15 women. The following should appear in the console.

> prediction
1 2 3 4 5 6 7
58.75712 59.33162 60.19336 61.05511 61.91686 62.77861 63.64035
8 9 10 11 12 13 14
64.50210 65.65110 66.51285 67.66184 68.81084 69.95984 71.39608
15
72.83233

Notice that the value of the first prediction is very close to what you just calculated by hand. The difference is due to rounding error.