【问题标题】:Implementing AIC score for multiple linear regression manually手动实现多元线性回归的 AIC 分数
【发布时间】:2020-03-16 19:38:45
【问题描述】:

我已经手动实现了一个多元线性回归类,现在我正在研究度量方法。我曾尝试手动计算 AIC 和 BIC 分数,但结果不正确。原因是我没有使用对数似然函数,而是使用了 SSE 方法。您能否建议我如何更改实现以计算完整的 AIC 和 BIC 分数?

这是我的方法现在的样子:

  def AIC_BIC(self, actual = None, pred = None):
    if actual is None:
      actual = self.response
    if pred is None:
      pred = self.response_pred

    n = len(actual)
    k = self.num_features

    residual = np.subtract(pred, actual)
    RSS = np.sum(np.power(residual, 2))

    AIC = n * np.log(RSS / n) + 2 * k
    BIC = n * np.log(RSS / n) + k * np.log(n)

    return (AIC, BIC)

请尝试给我一个手动方法,而不是图书馆电话。谢谢!

【问题讨论】:

标签: python python-3.x machine-learning linear-regression data-science


【解决方案1】:

在@James 的帮助下,我设法解决了这个问题。 这是我的新实现的样子:

 def LogLikelihood(self):
     n = self.num_obs
     k = self.num_features
     residuals = self.residuals

     ll = -(n * 1/2) * (1 + np.log(2 * np.pi)) - (n / 2) * np.log(residuals.dot(residuals) / n)

     return ll

  def AIC_BIC(self):
    ll = self.LogLikelihood()
    n = self.num_obs
    k = self.num_features + 1

    AIC = (-2 * ll) + (2 * k)
    BIC = (-2 * ll) + (k * np.log(n))

    return AIC, BIC

我实现了一个对数似然计算并将其用于公式中,该公式可在 Wikipedia 上找到。

【讨论】:

    猜你喜欢
    • 2018-05-01
    • 2010-11-23
    • 2021-07-19
    • 2017-01-21
    • 2013-07-17
    • 2014-05-20
    • 1970-01-01
    • 2019-06-03
    • 2016-10-15
    相关资源
    最近更新 更多