What is weighted least squares regression? How to perform it in python?
Weighted least squares regression is accustomed to correct for heteroscedasticity. During a Weighted regression procedure additional weight is given to the observations with smaller variance as a result of these observations give additional reliable info concerning the regression perform than those with massive variances.
import pandas as pd import statsmodels.api as sm
df= pd.read_csv('/content/sample_data/california_housing_train.csv') df.head()
We have to split the data in X and Y to fit it in the wls model.
Y=df['median_house_value'] X=df.drop(['median_house_value'], axis=1)
We will fit the dataset into the model and print the summary.
wls_model = sm.WLS(Y,X) results = wls_model.fit() print(results.summary())
If the weights square measure a operate of the info, then the post estimation statistics like fvalue and mse_model may not be correct, because the package doesn't nonetheless support no-constant regression.