Why predicted polynomial changes drastically when only the resolution of prediction grid changes?

后端 未结 2 1033
星月不相逢
星月不相逢 2021-01-20 19:14

Why I have the exact same model, but run predictions on different grid size (by 0.001 vs by 0.01) getting different predictions?

set.seed(0)         


        
2条回答
  •  感情败类
    2021-01-20 19:41

    In the first place, the predict lines don't fit the original data. You failed to make poly objs for prediction.

    ...
    poly_ori <- poly(x, poly_df)    # important
    ...   
    
    plot(x,y)
    
    x_plt1 = seq(-1, 1, 0.001)
    x_plt_exp1 = as.data.frame(poly(x_plt1, poly_df, coefs = attr(poly_ori, "coefs")))
    lines(x_plt1, predict(fit, x_plt_exp1),lwd = 3, col = 2)
    
    x_plt2 = seq(-1, 1, 0.01)
    x_plt_exp2 = as.data.frame(poly(x_plt2, poly_df, coefs = attr(poly_ori, "coefs")))
    lines(x_plt2, predict(fit, x_plt_exp2), lwd = 3, col = 3)
    

提交回复
热议问题