이 저장소는 교통 검지기 시계열 데이터에 대해 Deep Embedded Clustering(DEC) 기반 실험을 정리한 프로젝트입니다.
본 프로젝트는 KOTI 교통혼잡 예측 및 신호제어 과제의 실험 결과를 정리한 형태이며, Autoencoder로 특징을 추출한 뒤 DEC(Deep Embedded Clustering)로 교통 패턴을 군집화하는 파이프라인을 제공합니다. 모빌리티 데이터 내 잠재 패턴을 도출하는 비지도 딥러닝 모델 구현 프로젝트입니다.
- 입력 데이터: 정규화된 CSV(
input_normalize.csv) - 특징 추출: Autoencoder latent space(차원 축소)
- 군집화: DEC(Soft Assignment + KL loss)
- 산출물: 군집 라벨 예측, 정확도/ARI/NMI, 혼동행렬, 결과 엑셀 파일
- 운전자 행동 유형 군집화
- 수요 패턴 세분화
- AI 기반 운영 전략 수립
- 데이터 기반 서비스 고도화
기존 K-means 등의 군집 알고리즘은:
- 고차원 데이터에 취약
- 비선형 관계 반영 한계 존재
DEC는:
- 오토인코더 기반 특징 압축
- KL Divergence 기반 군집 정교화
를 통해 잠재 공간에서 구조적 패턴을 학습합니다.
- 입력 데이터 정규화
- 오토인코더 사전 학습
- 잠재공간 임베딩
- KL Divergence 최적화
- 군집 재조정
- 모빌리티 서비스 고객 세분화
- 위험도 기반 운전자 그룹화
- AI 기반 개인화 운영 전략 수립
dec_dense_layer.py- 노트북 코드를 실행 가능한 Python 스크립트로 정리한 메인 코드
0922Keras_DEC_DenseLayer-project.ipynb- 핵심 실험 노트북
Keras_DEC_DenseLayer.ipynb- 보조 실험 노트북
090202Keras_DEC_DenseLayer-project-Copy1.ipynb,090202Keras_DEC_DenseLayer-project-Copy2.ipynb- 과거 실험본(참고용)
metrics.pydec_dense_layer.py에서 사용되는 ACC / NMI / ARI 계산 모듈
requirements.txt- 실행 의존성
README.md- 프로젝트 설명서
.gitignore- 결과 산출물 예시:
...pdf,...xlsx,results/*.h5
cd F:\DEC_DLmodel
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt권장 환경: Python 3.7+
참고:
dec_dense_layer.py는metrics모듈을 import합니다. 실행 경로에metrics.py가 있어야 합니다.
- 경로 수정
dec_dense_layer.py에서 데이터 입력 경로와 결과 저장 경로를 현재 환경에 맞게 수정합니다.
trains = np.loadtxt("<input_normalize.csv 경로>", skiprows=1, delimiter=',', dtype=float)
...
df.to_excel('<결과 저장 경로>/result.xlsx', index=False)- 실행
python dec_dense_layer.py- 생성 결과 확인
- 가중치:
results/ae_weights.h5,results/DEC_model_final.h5 - 결과 파일:
result.xlsx - 학습/평가 지표: Acc, NMI, ARI, Confusion Matrix
n_clusters = 5- 기본값(실험 기준). 데이터 성격에 따라 조정 가능
- Autoencoder 구조 예시:
[input_dim, 500, 1000, 2000, 3000, 5000, 10] - Optimizer:
SGD- pretrain:
lr=0.1, momentum=0.9 - DEC fine-tune:
lr=0.01, momentum=0.9
- pretrain:
batch_size = 128pretrain_epochs = 1000maxiter = 20000,update_interval = 140,tol = 0.001
dec_dense_layer.py는 다음 순서로 동작합니다.
- CSV 로딩 및 전처리
- 현재 코드 기준:
[:,531:795]구간을 사용해 264차원 입력 생성
- 현재 코드 기준:
- Autoencoder 학습
- encoder 임베딩에 대해 KMeans로 초기 클러스터 중심 초기화
- DEC 모델 구성 (
ClusteringLayer, KL loss) - 반복 학습
q(soft assignment) 계산 후 보조 분포p갱신delta_label < tol기준으로 조기 종료
- 테스트 추론 및 지표 계산
- 결과 엑셀 저장 및 시각화
- 연구 실험 목적 코드이므로, 운영 적용 전에는 경로, 라벨 정의, 군집 개수, 피처 범위를 재확인하세요.
- 한글 경로/인코딩 이슈가 있으면 영문 경로에서 실행하는 것을 권장합니다.
별도의 라이선스 파일이 없어 배포 전 라이선스 정책을 지정해 주세요.
This repository contains Deep Embedded Clustering (DEC)-based experiments on traffic detector time-series data.
This project organizes experimental work from a KOTI traffic congestion prediction and signal control task and provides a pipeline that applies DEC on top of Autoencoder-based feature representations.
- Input: normalized CSV (
input_normalize.csv) - Feature extraction: Autoencoder latent space (dimensionality reduction)
- Clustering: DEC (Soft Assignment + KL loss)
- Outputs: cluster predictions, Accuracy/NMI/ARI, confusion matrix, and result spreadsheets.
dec_dense_layer.py- Main executable Python script converted from the notebook workflow
0922Keras_DEC_DenseLayer-project.ipynb- Core experiment notebook
Keras_DEC_DenseLayer.ipynb- Supporting experiment notebook
090202Keras_DEC_DenseLayer-project-Copy1.ipynb,090202Keras_DEC_DenseLayer-project-Copy2.ipynb- Legacy experiment copies for reference
metrics.py- Metrics helper module used by
dec_dense_layer.py(ACC/NMI/ARI)
- Metrics helper module used by
requirements.txt- Runtime dependencies
README.md- Project documentation
.gitignore- Example outputs:
...pdf,...xlsx,results/*.h5
cd F:\DEC_DLmodel
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txtRecommended: Python 3.7+
Note:
dec_dense_layer.pyimportsmetrics; ensuremetrics.pyis available in the runtime path.
- Update paths
Modify dataset input and output paths in dec_dense_layer.py for your environment.
trains = np.loadtxt("<path to input_normalize.csv>", skiprows=1, delimiter=',', dtype=float)
...
df.to_excel('<path to output>/result.xlsx', index=False)- Run
python dec_dense_layer.py- Check outputs
- Weights:
results/ae_weights.h5,results/DEC_model_final.h5 - Result file:
result.xlsx - Logs / metrics: Accuracy, NMI, ARI, Confusion Matrix
n_clusters = 5- Default from current experiment; adjust based on data and task goals
- Autoencoder architecture example:
[input_dim, 500, 1000, 2000, 3000, 5000, 10] - Optimizer:
SGD- pretrain:
lr=0.1, momentum=0.9 - DEC finetune:
lr=0.01, momentum=0.9
- pretrain:
batch_size = 128pretrain_epochs = 1000maxiter = 20000,update_interval = 140,tol = 0.001
dec_dense_layer.py follows this workflow:
- Load and preprocess CSV
- Current code uses the slice
[:,531:795]to build a 264-dimensional feature vector
- Current code uses the slice
- Train Autoencoder
- Initialize DEC cluster centers using KMeans on encoder embeddings
- Build DEC model (
ClusteringLayer, KL loss) - Iterative training
- Update soft assignments
qand auxiliary target distributionp - Stop when convergence condition
delta_label < tolis met
- Update soft assignments
- Run inference on test set and compute metrics
- Export output spreadsheet and visualizations
- This is a research-oriented codebase. Before production use, validate input paths, label definitions, number of clusters, and feature ranges.
- If you face path/encoding issues, especially with Korean paths, use ASCII-only directories for stable execution.
No separate license file is provided. Please define your license policy before external distribution.
