Feature: Historical Data Analysis
Relevant source files
The following files were used as context for generating this wiki page:
- SVM_MODEL_DOCUMENTATION.md
- dashboard-next/DASHBOARD_STRUCTURE.md
- dashboard-next/app/api/layers/route.ts
- dashboard-next/app/api/analytics/targets/route.ts
- dashboard-next/app/dataset/page.tsx
- dashboard-next/app/settings/page.tsx
- PERFORMANCE_OPTIMIZATION_REPORT.md
- UNIFIED_SCORING_SYSTEM.md
- dashboard-next/MENU_GUIDE.md
The Historical Data Analysis feature provides fast, consistent, and cost-effective sentiment analysis based on a static, pre-processed dataset. It is a core component of the project's Dual Model Architecture, where it complements the real-time analysis performed by the Gemini AI model. This system uses a custom-trained Support Vector Machine (SVM) model to power various analytical pages on the dashboard, offering insights into a historical snapshot of YouTube comments.
The primary goal is to deliver reliable batch analysis for research and trend-spotting, leveraging a cleaned and manually labeled dataset for high domain-specific accuracy. This contrasts with the live analysis system, which handles raw, unprocessed comments in real-time.
Sources: README.md, SVM_MODEL_DOCUMENTATION.md, CHANGELOG.md.
Architecture Overview
The historical analysis system is built around a simple and efficient architecture: a static CSV file serves as the database, which is read and processed by Next.js API Routes on-demand. The results are then served as JSON to the frontend React components for visualization.
The data flow for historical analysis is as follows:
This diagram shows how various API routes consume the static CSV data to serve different frontend pages.
A key performance feature is the multi-layer caching strategy implemented to minimize redundant data processing. The /api/stats endpoint, for example, uses an in-memory cache with a 5-minute duration to avoid re-parsing the large CSV file on every request.
Sources: SVM_MODEL_DOCUMENTATION.md, PERFORMANCE_OPTIMIZATION_REPORT.md:11-21, dashboard-next/app/api/layers/route.ts.
Data Source & Preprocessing
The foundation of the historical analysis is a static, processed CSV file containing YouTube comments.
- Data File:
comments_fixed_labels.csv - Location:
/data/processed/ - Total Records: 19,228 comments
The data undergoes a significant preprocessing pipeline before being used for model training and analysis:
- Text Normalization: Text is converted to lowercase. URLs, mentions, and hashtags are removed.
- Slang Conversion: Common Indonesian slang words (e.g.,
gak,bgt) are replaced with their formal equivalents (tidak,sangat). - Feature Extraction: A
TfidfVectorizeris used to convert the text into numerical features. This vectorizer is configured to consider the 5,000 most frequent features and uses n-grams of 1 to 2 words.
Sources: SVM_MODEL_DOCUMENTATION.md:11-36, dashboard-next/MENU_GUIDE.md:105-106, dashboard-next/app/api/layers/route.ts:8.
Core Engine: SVM Model
The sentiment classification for the historical dataset is performed by a Support Vector Machine (SVM) model. This model is specifically trained on the cleaned, domain-specific dataset to ensure high accuracy for comments related to Indonesian football.
Model Configuration
The model is implemented as a scikit-learn Pipeline that combines feature extraction and classification.
| Parameter | Value | Description |
|---|---|---|
| Model Type | SVC (Support Vector Classifier) | The core classification algorithm. |
| Kernel | rbf (Radial Basis Function) | A non-linear kernel for complex data. |
| C | 1.0 | Regularization parameter. |
| Gamma | scale | Kernel coefficient. |
| Vectorizer | TfidfVectorizer | Converts text to feature vectors. |
max_features | 5000 | Limits the vocabulary size. |
ngram_range | (1, 2) | Considers both single words and bigrams. |
Sources: SVM_MODEL_DOCUMENTATION.md:39-55, dashboard-next/app/settings/page.tsx:50-62.
Model Performance
The performance metrics displayed on the dashboard reflect the model's effectiveness on the test set.
| Metric | Value | Source Page |
|---|---|---|
| Accuracy | 89.4% | /settings |
| F1-Score | 91% | /settings |
| Confidence | 92% | /settings |
Note: These values are taken from the frontend display and may differ slightly from metrics in raw model documentation due to different reporting contexts (e.g., cross-validation vs. test set).
Sources: dashboard-next/app/settings/page.tsx:20-28, dashboard-next/app/dataset/page.tsx:36-40, SVM_MODEL_DOCUMENTATION.md:60-67.
Backend API Endpoints
Several API endpoints are dedicated to serving processed historical data to the frontend.
GET /api/layers
This endpoint reads the comments_fixed_labels.csv file and computes aggregated statistics for four distinct analytical "layers": sentiment, target of criticism, emotion, and constructiveness. It returns the counts, percentages, and associated accuracy for each category within these layers.
Response Structure (Example for sentiment layer):
{
"sentiment": [
{ "name": "Negative", "value": 13421, "percentage": 69.8, "color": "#ef4444", "accuracy": 89.4 },
{ "name": "Positive", "value": 5595, "percentage": 29.1, "color": "#22c55e", "accuracy": 89.4 },
{ "name": "Neutral", "value": 212, "percentage": 1.1, "color": "#6b7280", "accuracy": 89.4 }
],
"target": [...],
"emotion": [...],
"constructiveness": [...]
}
Sources: dashboard-next/app/api/layers/route.ts.
GET /api/analytics/targets
This endpoint provides statistics grouped by the target_kritik column in the dataset. It can return data for all targets or for a specific target if a query parameter is provided.
Parameters:
| Parameter | Type | Description |
|---|---|---|
target | string (optional) | The specific target to retrieve details for (e.g., 'PSSI'). |
Data Flow:
This sequence diagram illustrates how the /api/analytics/targets endpoint processes a request.
Sources: dashboard-next/app/api/analytics/targets/route.ts.
Frontend Visualization & Pages
The historical data is visualized across several dedicated pages in the dashboard, following a "Progressive Disclosure" design philosophy where users can move from a high-level overview to in-depth analysis.
| Page Route | Page Name | Purpose |
|---|---|---|
/ | Dashboard | Provides a high-level overview with key metrics (total comments, sentiment distribution) and AI insights. |
/sentiment | Sentiment Analysis | Details sentiment broken down by target of criticism and constructiveness. |
/emotions | Emotion Insights | Offers a deep dive into the distribution and intensity of emotions within the comments. |
/comments | Comments Explorer | Allows users to browse, search, and filter the raw 19,000+ comments. |
/model | Model Performance | Displays technical metrics of the SVM model, including a classification report. |
/dataset | Dataset | Shows metadata about the training dataset, including source, size, and sentiment distribution. |
Sources: dashboard-next/DASHBOARD_STRUCTURE.md:9-80, dashboard-next/MENU_GUIDE.md:20-170.
Conclusion
The Historical Data Analysis feature is a robust and efficient system for exploring a large, static set of sentiment data. By leveraging a custom-trained SVM model and a simple file-based architecture with performance optimizations like caching, it provides a fast, consistent, and zero-cost analysis platform. It serves as the analytical backbone for the dashboard's historical views, perfectly complementing the dynamic, real-time capabilities of the live analysis system.
Sources: SVM_MODEL_DOCUMENTATION.md, README.md.