Write a Pandas program to compute the autocorrelations of a given numeric series

  • برمجة بايثون

Write a Pandas program to compute the autocorrelations of a given numeric series.

From Wikipedia:
Autocorrelation, also known as serial correlation, is the correlation of a signal with a delayed copy of itself as a function of delay. Informally, it is the similarity between observations as a function of the time lag between them

الأجوبة

import pandas as pd
import numpy as np
num_series = pd.Series(np.arange(15) + np.random.normal(1, 10, 15))
print("Original series:")
print(num_series)
autocorrelations = [num_series.autocorr(i).round(2) for i in range(11)]
print("\nAutocorrelations of the said series:")
print(autocorrelations[1:])
Python

Sample Output:

Original series:
0     13.207262
1      4.098685
2     -1.435534
3     13.626760
4     -1.435962
5     28.823612
6     -3.299048
7     14.048354
8      6.991233
9     13.289209
10    23.032654
11     7.080452
12    -2.453857
13    -2.346193
14    17.873884
dtype: float64

Autocorrelations of the said series:
[-0.38, 0.1, -0.43, 0.03, 0.35, -0.2, 0.04, -0.59, 0.34, 0.11]
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...