def question_4(data):
    ' Fitting model for different values of `k` '
    data = data[(data['Country'] == 'Israel')]
    (train_X, train_y, test_X, test_y) = split_train_test(data['DayOfYear'], data['Temp'])
    losses = np.array([])
    for k in range(1, 11):
        poly_fit = PolynomialFitting(k)
        poly_fit.fit(train_X.to_numpy(), train_y.to_numpy())
        loss = poly_fit.loss(test_X.to_numpy(), test_y.to_numpy())
        losses = np.append(losses, round(loss, 2))
        print(k, loss)
    fig = px.bar(x=range(1, 11), y=losses, width=1500, height=700, labels={'x': 'Polynomials Degrees (k)', 'y': 'Test Error (MSE)'}, title='Q4 Test Errors for Different Polynomials Degrees (k)')
    fig.data[(- 1)].text = losses
    fig.update_xaxes(tick0=1, dtick=1)
    fig.update_traces(textposition='outside')
    fig.show()
Fitting model for different values of `k`
def question_4(data):
    '  '
    data = data[(data['Country'] == 'Israel')]
    (train_X, train_y, test_X, test_y) = split_train_test(data['DayOfYear'], data['Temp'])
    losses = np.array([])
    for k in range(1, 11):
        poly_fit = PolynomialFitting(k)
        poly_fit.fit(train_X.to_numpy(), train_y.to_numpy())
        loss = poly_fit.loss(test_X.to_numpy(), test_y.to_numpy())
        losses = np.append(losses, round(loss, 2))
        print(k, loss)
    fig = px.bar(x=range(1, 11), y=losses, width=1500, height=700, labels={'x': 'Polynomials Degrees (k)', 'y': 'Test Error (MSE)'}, title='Q4 Test Errors for Different Polynomials Degrees (k)')
    fig.data[(- 1)].text = losses
    fig.update_xaxes(tick0=1, dtick=1)
    fig.update_traces(textposition='outside')
    fig.show()