What is Durbin Watson test? How to perform it in python.
Durbin Watson test includes statistics, and it is equal to 2*(1-r), where r is autocorrelation between residual. When test statistic equals 2 no autocorrelation. When closer to 0 evidence of positive correlation, when closer to 4 evidence of negative correlation.
Durbin watson test is defined as:-
import pandas as pd from statsmodels.formula.api import ols from statsmodels.stats.stattools import durbin_watson
df= pd.read_csv('/content/sample_data/california_housing_train.csv') df.head()
Before applying durbin-watson test we have to apply OLS on some column particularly.
model=ols('total_bedrooms ~ housing_median_age + total_bedrooms + households',data=df).fit() print(model.summary())
As we can see the value is closer to 0 it is more evident of positive correlation.