All problems
AIC and BIC
Problem
Compute the Akaike and Bayesian information criteria for a linear model: AIC = n*ln(RSS/n) + 2k and BIC = n*ln(RSS/n) + k*ln(n), where k is the number of parameters.
Clip RSS to at least 1e-12 before taking the log. Return [aic, bic]; n <= 0 returns [0.0, 0.0].
Hint
Both criteria reward fit through ln(RSS/n); BIC punishes parameters more heavily via ln(n).
Test cases
case 1
in: [10,2,3]
expected: [-10.094379124341003,-9.186623845358866]
case 2
in: [100,50,2]
expected: [-65.31471805599453,-60.104377684018345]
case 3
in: [5,0,1]
expected: [-144.20229514181324,-144.59285722937915]
case 4
in: [0,1,1]
expected: [0,0]
Starter codePython
import math
def aic_bic(n, rss, k):
# Returns [aic, bic]
# Your code here
pass4 test cases · run your code against them in the editor