Probability with R. Jane M. Horgan
Чтение книги онлайн.
Читать онлайн книгу Probability with R - Jane M. Horgan страница 24
lm(prog2∼prog1)
calculates what is referred to as the linear model (lm) of
that best fits the data.
The output is
Call: lm(formula = prog2∼prog1) Coefficients: (Intercept) prog1 -5.455 0.960
Therefore, the line that best fits these data is
To draw this line on the scatter diagram, write
plot(prog2, prog1) abline(lm(prog2∼prog1))
which gives Fig. 3.16.
Figure 3.16 The Line of Best Fit
The line of best fit may be used to make predictions. For example, we might be able to predict how students will do in Semester 2 from the results that they obtained in Semester 1. If the mark on Programming 1 for a particular student is 70, that student would be expected to do well also in Programming 2, estimated to obtain
A word of warning is appropriate here. The estimated values are based on the assumption that the past trend continues. This may not always be the case. For example, students who do badly in Semester 1, may get such a shock that they work harder in Semester 2, and change the pattern. Similarly, students getting high marks in Semester 1 may be lulled into a sense of false security and take it easy in Semester 2. Consequently, they may not do as well as expected. Hence, the Semester 1 trends may not continue, and the model may no longer be valid.
3.6 MACHINE LEARNING AND THE LINE OF BEST FIT
Machine learning is the science of getting computer systems to use algorithms and statistical models to study patterns and learn from data. Supervised learning is the machine learning task of using past data to learn a function in order to predict a future output.
The line of best fit is one of the many techniques that machine learning has borrowed from the field of Probability and Statistics to “train” the machine to make predictions. In this case of what is also known as the simple linear regression line in statistics, a set of pairs
Often, the data for supervised learning are randomly divided into two parts, one for training and the other for testing. In machine learning, we derive the line of best fit from the training set
The testing set is used to see how well the line actually fits. Usually, an
Example 3.1
Suppose there are 50 pairs
TABLE 3.1 The Training Set
Observation Numbers |
|
|
Observation Numbers |
|
|
1 | 11.8 | 31.3 | 21 | 15.1 | 80.1 |
2 | 10.8 | 59.9 | 22 | 14.7 | 66.9 |
3 | 8.6 | 27.6 | 23 | 10.5 |
42.0
|