WLS

Weighted rain.

Weighted least squares down-weights noisy rows. Print WLS vs OLS slope.

Goal

Weight later months more and print params.

import pandas as pd
import statsmodels.api as sm
df = pd.DataFrame({'x': [1.0, 2, 3, 4], 'y': [80.0, 60, 110, 90]})
w = [1, 1, 3, 3]
ols = sm.OLS(df['y'], sm.add_constant(df['x'])).fit()
wls = sm.WLS(df['y'], sm.add_constant(df['x']), weights=w).fit()
print('ols', ols.params.round(3).to_dict())
print('wls', wls.params.round(3).to_dict())
import pandas as pd
import statsmodels.api as sm
print(sm.WLS([1, 2, 3], sm.add_constant([1, 2, 3]), weights=[1, 1, 1]).fit().params.round(3).to_dict())
import numpy as np
print(np.average([80, 60, 110], weights=[1, 1, 3]))
import pandas as pd
print(pd.Series([1, 2, 3]))