Below code snippet can give idea on the data
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.graphics.tsaplots import plot_acf
from pandas.plotting import autocorrelation_plot
# Generate white noise data
np.random.seed(42)
data_low_corr = np.random.randn(500)
df_low_corr = pd.DataFrame(data_low_corr, columns=['value'])
# Plot autocorrelation
plot_acf(df_low_corr)
plt.show()
autocorrelation_plot(df_low_corr)
plt.show()
pd.plotting.lag_plot(df_low_corr, lag = 1)
plot_acf(df_low_corr, alpha = 0.05)
Now below gives snippet for no correlation
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from statsmodels.graphics.tsaplots import plot_acf
# Generate random data
np.random.seed(42)
data_no_corr = np.random.uniform(size=100)
df_no_corr = pd.DataFrame(data_no_corr, columns=['value'])
# Plot autocorrelation
# plot_acf(df_no_corr)
# plt.show()
from pandas.plotting import autocorrelation_plot
autocorrelation_plot(df_no_corr)
plt.show()
pd.plotting.lag_plot(df_no_corr, lag = 1)
plot_acf(df_no_corr, alpha = 0.05)
The plots look like the below
Below is with High correlation
nt_array = pd.array([1, 2, 3, 4, 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25], dtype='int')
print(int_array)
print()
df_no_corr = pd.DataFrame(int_array, columns=['value'])
# Plot autocorrelation
# plot_acf(df_no_corr)
# plt.show()
from pandas.plotting import autocorrelation_plot
autocorrelation_plot(df_no_corr)
plt.show()
pd.plotting.lag_plot(df_no_corr, lag = 1)
plot_acf(df_no_corr, alpha = .05)
No comments:
Post a Comment