시작은 미약하였으나 , 그 끝은 창대하리라

[시계열 데이터] 해석 기법 본문

새롭게 알게된_tech/파이썬_tech

[시계열 데이터] 해석 기법

애플파ol 2023. 8. 3. 14:41

시계열 데이터를 해석하는 방법에 알아보려 한다.

 

1.  Heatmap

# 1. 데이터에서 원하는 feature들만 추출 하여서, 딕셔너리 형태로 만들어줌.

data_dict = {
    'featrue_1': amp,
    'featrue_2': voltage,
    'featrue_3': tem,
    'featrue_4 ': nu,
    'featrue_5 ': cu
}

# 2. DataFrame의 형식으로 변환
df = pd.DataFrame(data_dict)

# 3. heatmap으로 표현.
plt.rc('font', size=12)        # 기본 폰트 크기
plt.rc('axes', labelsize=13)   # x,y축 label 폰트 크기      
plt.rc('xtick', labelsize=13)  # x축 눈금 폰트 크기 
plt.rc('ytick', labelsize=13)  # y축 눈금 폰트 크기

plt.figure(figsize=(10, 8))  # Adjust the figure size if needed
# annot = 숫치 표기 유무,
sns.heatmap(df.corr(), annot=True, cmap='coolwarm',linewidths = 0.1,linecolor = "white")
plt.title('Correlation Heatmap of Features')

# Show the heatmap
plt.show()

결과 , 숫자가 클수록 양의 상관관계를 갖고 있는것이고, 숫자가 작을수록 음의 상관관계를 갖고 있는 것이다. 0 일때는 관련이 없음.

2. Recurrence plot

참고논문 :  'Classification of Time-Series Images Using Deep Convolutional Neural Networks'

참고 블로그: https://blog.naver.com/rkdwnsdud555/221380407792

정의: 시계열 데이터를 m차원의 공간궤적에 나타낸 후 공간궤적에 위치한 점간의 거리를 이미지로 나타낸 것.

 

import pylab as plt
import numpy as np

def rec_plot(s, eps=None, steps=None):
    if eps==None: eps=0.01
    if steps==None: steps=10
    N = s.size
    S = np.repeat(s[None,:], N, axis=0)
    Z = np.floor(np.abs(S-S.T)/eps)
    Z[Z>steps] = steps

    return Z

s = np.random.random(1000)
plt.imshow(rec_plot(s))
plt.show()

 

recurrence plot 결과

 

 

3. GramianAngularField

참고 사이트: https://pyts.readthedocs.io/en/stable/generated/pyts.image.RecurrencePlot.html

정의 : 시계열의 각 값 쌍 사이의 일종의 시간적 상관 관계를 이미지로 나타냄.

import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
from pyts.image import GramianAngularField


data= 넣고싶은 데이터 작성.

x = np.sin(data)
X = np.array([x])
print(len(X))

# GAF transformations
image_size = 24
gasf = GramianAngularField(image_size,method='summation')
X_gasf = gasf.fit_transform(X)
gadf = GramianAngularField(image_size,method='difference')  
X_gadf = gadf.fit_transform(X)

# Show the results for the first time series
plt.figure(figsize=(16, 8))
plt.subplot(121)
plt.imshow(X_gasf[0], cmap='rainbow', origin='lower',vmin=-1., vmax=1.)
colorbar = plt.colorbar(fraction=0.046)
plt.title("GASF", fontsize=16)
# plt.title("Gramian Angular Field", fontsize=16)
# plt.colorbar(im, cax=grid.cbar_axes[0])

plt.subplot(122)
plt.imshow(X_gadf[0], cmap='rainbow', origin='lower',vmin=-1., vmax=1.)
colorbar = plt.colorbar(fraction=0.046)
plt.title("GADF", fontsize=16)
# plt.title("Gramian Angular Field", fontsize=16)
plt.show()

 

 

 

 

4.  산점도 분석. 

Feature간의 특징이 어떤 관계를 갖는지 시각적으로 확인함.

import seaborn as sns
import matplotlib.pyplot as plt

data_dict = {
    'Feature_1': amp,
    'Feature_2': voltage,
    'Feature_3': temp,
    'Feature_4 ': nu,
    'Feature_5': cu
}


df = pd.DataFrame(data_dict)


sns.set(style='whitegrid')
sns.pairplot(df[['Feature_1', 'Feature_2', 
                     'Feature_3', 'Feature_4 ']])
plt.show()

Comments