如何降低广义线性模型训练误差

spanish |浏览47次
收藏|2019/01/12 01:34
  • 问题补充 : 2019/01/12 01:36

    我在尝试用StMoMo package来跑一个GLM,但它的训练误差实在是太大了。有什么比较普遍的方法可以降低这种误差?谢谢。






    library(StMoMo)

    EWMaleIniData <- central2initial(EWMaleData)

    ages.fit <- 55:89

    wxt <- genWeightMat(ages = ages.fit, years = EWMaleIniData$years, clip = 3)


    # Setting up constrain function

    constLC <- function(ax, bx, kt, b0x, gc, wxt, ages){c1 <- mean(kt[1, ], na.rm = TRUE)

    c2 <- sum(bx[, 1], na.rm = TRUE)

    list(ax = ax + c1 * bx, bx = bx / c2, kt = c2 * (kt - c1))}


    # Setting up link function

    LC <- StMoMo(link = "logit", staticAgeFun = TRUE, periodAgeFun = "NP", constFun = constLC)


    # Fit the model

    LCfit <- fit(LC, data = EWMaleIniData, ages.fit = ages.fit, wxt = wxt, ridge = 1e-08)


    ax = LCfit$ax

    bx = LCfit$bx

    kt = LCfit$kt


    # Create a fitted matrix to compare

    FittedValues = matrix(ncol = ncol(kt), nrow = nrow(ax))

    colnames(FittedValues) = colnames(kt)

    rownames(FittedValues) = rownames(ax)


    # Populate the fitted matrix

    for(i in 1:nrow(ax))

      {

      

        for(j in 1:ncol(kt))

        {

          FittedValues[i,j] = exp(ax[i] + bx[i] * kt[j])

        }

    }


    ActualValues = EWMaleIniData$Dxt[ages.fit,]/EWMaleIniData$Ext[ages.fit,]


    # Calculate percent errors from fitted

    PctErr = (FittedValues - ActualValues)/ActualValues*100


    View(PctErr)


回答该问题即可获得 2 经验值,问题被采纳即可获得 5 经验值 + 2 财富值!
我来回答
全部回答(0)
0人关注该问题
+1
 加载中...