A -> hash function -> Alpha
B -> hash function -> Bravo
C -> hash function -> Cycle
위 모습처럼 임의의 길이를 갖는 데이터를 고정된 길이의 데이터로 매핑하는 단방향 함수이다.
Key - Value 쌍 구조를 가지는 dictionary의 실질적 사용 형태로 이해하면 된다.
Key를 hash function에 넣어 value에 mapping하는 것 으로 이해하면 된다.
일반적으로 감성 분석 결과 데이터 형태는 다음과 같다.
{'id': 1, 'sentiment': 'positive', 'timestamp': '2024-12-01T14:00:00Z'}
{'id': 2, 'sentiment': 'negative', 'timestamp': '2024-12-01T15:00:00Z'}
목적: 텍스트 데이터 감성 분석 결과를 시간 단위로 집계하여 시계열 예측 모델 만들기
방법:
키(key)로 설정값(value)으로 저장코드 예시
hash_table = {} for result in sentiment_results: time_key = result['timestamp'][:13] # YYYY-MM-DD HH까지만 추출 sentiment = result['sentiment'] if time_key not in hash_table: hash_table[time_key] = {'positive': 0, 'negative': 0, 'neutral': 0} hash_table[time_key][sentiment] += 1
{
'2024-12-01 14': {'positive': 5, 'negative': 2, 'neutral': 3},
'2024-12-01 15': {'positive': 3, 'negative': 4, 'neutral': 2}
}
시간: '2024-12-01 14:00', 긍정 감정: 5, 부정 감정: 2, 중립 감정: 3
데이터를 위 모습(시계열)으로 바꾸면 시계열 모델링을 통해 향후 트렌드 예측 그래프를 만들어낼 수 있다.
이는 여론 트렌드 분석에 사용된다.