Continue with the example in the second note.
3. Continuous iteration and exploration process
As shown in the previous figure, a straight line does not represent the trend after week4. Since the first-order function does not work, let's try the second-order function?
F (x) = AX ** 2 + bx + c
Continue to use the polyfit function to determine the values of A, B, and C:
f2p =sp.polyfit(x,y,2) print f2p
The code above gets an array
[1.05322215e-02-5.26545650e + 00 1.97476082e + 03], which is the values of A, B, and C respectively.
f2 = sp.poly1d(f2p) print(error(f2,x,y))
Continue to calculate the sum of squares of the residual values: 179983507.878, which is obviously better than once. If the order is higher, the effect will be better. Why don't we increase the order further?
Try the case where the order number is 3, 10, 100
f3 = sp.poly1d(sp.polyfit(x, y, 3)) f10 = sp.poly1d(sp.polyfit(x, y, 10)) f100 = sp.poly1d(sp.polyfit(x, y, 100)) print ‘d3=‘ ,(error(f3,x,y)) print ‘d10=‘ ,(error(f10,x,y)) print ‘d100=‘ , (error(f100,x,y))
The sum of the squares of the residual values is as follows:
D3 = 139350144.032.
D10 = 121942326.364
D100 = 109452403.459
The results are getting better and better, but does the 100-item model really represent the real user behavior? We will continue to draw the picture.
The purple curve represents the 100 degree polynomial. Do you see the problem? The jitter is so bad! Responding to the requirements of all data, however, there is actually a lot of data in it, such as a point that is too far away, not representative. Such fitting is called overfitting, and the 10th order is similar (if there is more data, the effect will be more obvious ). Therefore, increasing the complexity of the model is not a good solution.
Where is the problem? From the modeling perspective, it seems that there are some bottlenecks. Let's look at the data. Do we really understand the data?
Machine Learning System Design-Reading Notes 3