Solutions

1. Load the data


In [ ]:
bmi_life_data = pd.read_csv('bmi_and_life_expectancy.csv')

2.Build a linear regression model


In [ ]:
def linear_regression(x, y):
    m=1
    b=0
    for epoch in range(epochs):
        for i in range(len(x)):
            pred = m*x[i] + b
            diff = y[i] - pred
            m += m*diff*learning_rate
            b += diff*learning_rate
    return m, b

3. Predict using the model


In [ ]:
def predict(m, b, bmi):
    return m[0]*bmi + b[0]

m, b = linear_regression(x, y)
predict(m, b, 21.07931)

In [ ]: