Skip to content
DeepForgeby svx
All problems
EasyStatisticsst-189

Log-Linear Fit

Problem

Return the slope of ln(y) regressed on x by least squares, which estimates the exponential growth rate. Return 0.0 when the lists are shorter than two, lengths differ, any y <= 0, or x has zero variance.

Hint

Take logs first, then run an ordinary least squares slope.

Test cases

case 1
in: [[1,2,3],[10,100,1000]]
expected: 2.3025850929940455
case 2
in: [[0,1,2],[1,2.718281828459045,7.38905609893065]]
expected: 1
case 3
in: [[1,2,3],[5,5,5]]
expected: 0
case 4
in: [[1,2],[1,2]]
expected: 0.6931471805599453
case 5
in: [[1,2,3],[1,0,1]]
expected: 0
Starter codePython
import math
def log_linear_fit(x, y):
    # Your code here
    pass

5 test cases · run your code against them in the editor