Machine Learning
Predictive Models, Classification and Clustering
This page is populated during Milestone 3 (Week 6) with ML findings.
Overview
We developed two machine learning models to understand Reddit post dynamics:
- Classification Model (Q8): Predicting whether a post will receive high engagement (score ≥ 10)
- Regression Model (Q9): Predicting final post popularity based on early engagement metrics
- Clustering Model (Q10): An unsupervised TF-IDF + KMeans approach used to group posts into natural themes (e.g., general job discussions, HR issues, early-career experiences, cybersecurity, and job-offer decisions).
Question 1: Can We Predict High Engagement Posts?
Question: Can we predict whether a post will receive high engagement based on its content and metadata?
Problem Formulation
- Task Type: Binary Classification
- Target Variable:
high_engagement(1 if score ≥ 10, else 0) - Evaluation Metrics: AUC, Accuracy, F1 Score
- Dataset: 1% sample from S3 submissions data
Feature Engineering
Features Used:
- Text Features: TF-IDF representation of title + selftext (65,536 features via HashingTF)
- Metadata Features:
text_len: Total character count of title and selftexthour_of_day: Hour when post was created (0-23)
Pipeline: Tokenizer → StopWordsRemover → HashingTF → IDF → VectorAssembler
Model Performance
Results:
| Model | AUC | Accuracy | F1 Score |
|---|---|---|---|
| Logistic Regression | 0.665 | 0.724 | 0.772 |
| Random Forest | 0.590 | 0.901 | 0.853 |
Key Findings:
- Logistic Regression achieves better AUC (0.665), indicating more balanced predictions across both classes
- Random Forest shows higher Accuracy (0.901) and F1 (0.853), but lower AUC suggests it is biased toward the majority class (low engagement posts)
- Selected Model: Logistic Regression is chosen as the final model due to better generalization and balanced performance (higher AUC)
Business Question 2: Can Early Engagement Metrics Predict Final Popularity?
Question: Can we predict a post’s final popularity based on its engagement patterns in the first hour?
Problem Formulation
- Task Type: Regression
- Target Variable:
log1p(final_score)(log-transformed final score of each submission)
- Evaluation Metrics: RMSE, MAE, R²
- Dataset: Posts with at least one comment in the first hour
Feature Engineering
Features Used:
Early Engagement Features (from first-hour comments)
early_comment_count_1h: Number of comments in first hourearly_comment_score_sum_1h: Total comment score in first hourearly_comment_score_avg_1h: Average comment score in first hour
Post Content & Metadata
title_len: Character length of post titleselftext_len: Character length of post bodyis_self_flag: Whether post is text-only (vs. link)
Hypothesis: Posts that generate high-quality early discussion (measured by comment scores) will achieve greater long-term popularity.
Model Performance
| Model | RMSE | MAE | R² |
|---|---|---|---|
| Linear Regression | 1.8026 | 1.2881 | 0.3154 |
| Gradient Boosted Trees | 1.5478 | 0.8228 | 0.4952 |
Best Model: Gradient Boosted Trees achieves lowest RMSE and explains nearly 50% of variance in final popularity.
Feature Importance (Gradient Boosted Trees)
| Rank | Feature | Importance |
|---|---|---|
| 1 | early_comment_score_avg_1h |
0.4241 |
| 2 | title_len |
0.1765 |
| 3 | selftext_len |
0.1385 |
| 4 | early_comment_score_sum_1h |
0.1282 |
| 5 | early_comment_count_1h |
0.1052 |
| 6 | is_self_flag |
0.0275 |
Key Insight: The quality of early comments (average score) is more predictive than quantity alone, accounting for 42% of model importance.
Model Comparison
| Model | Strengths | Weaknesses |
|---|---|---|
| Linear Regression | Simple, interpretable, fast training | Underfits nonlinear relationships between early and final engagement |
| Gradient Boosted Trees | Captures complex nonlinear patterns, best predictive accuracy | Less interpretable, longer training time |
Question 3: Can We Group Posts into Natural Clusters?
Question: Can Reddit job-related posts be automatically grouped into meaningful semantic clusters based on their text content?
Analysis Type: Unsupervised Learning — KMeans Clustering
Problem Formulation
- Task Type: Unsupervised Topic Discovery
- Goal: Identify latent themes among Reddit job-related posts
- Input Data: Cleaned submissions (text_clean) from 1% S3 sample
- Methods:
- Tokenizer → StopWordsRemover → HashingTF → IDF
- KMeans (k = 5)
- PCA (2D) for visualization
The objective is to understand whether semantically similar posts cluster together, revealing thematic groups such as workplace rants, job search questions, or career guidance.
Visualization
PCA 2D Scatter Plot
This plot shows the 2-dimensional PCA projection of TF-IDF vectors. Despite dimensionality reduction, clusters remain distinguishable at the edges while most posts form a dense central group.
Subreddit Distribution Across Clusters
Cluster 0 dominates across all subreddits, suggesting a large “general topic” cluster. Smaller clusters represent more specific themes.
Cluster Interpretation
Cluster 0 — General Job Discussions & Advice
Top Words: job, work, like, want, know, company, time, working, get
Subreddits represented: jobs, careerguidance, antiwork, resumes, recruitinghell
Interpretation:
Cluster 0 contains the majority of samples and represents the most general-purpose job-related conversations, including:
- Job search questions
- Basic career advice
- General complaints about work
- “Should I take this job?” discussions
- Resume / application help
This cluster captures the broad, everyday content commonly shared across all subreddits, explaining why nearly all groups map heavily into Cluster 0.
Cluster 1 — HR / Access / Workplace Policy Issues
Top Words: suspension, access, currently, people, never, someone, suspended
Interpretation:
A smaller, more specialized cluster focused on:
- Workplace suspension
- Access removal
- Employment compliance issues
- HR investigations
These posts often come from users who unexpectedly lost access to workplace systems and seek help.
Cluster 2 — Early Career & Accounting Work Experiences
Top Words: really, working, accounting, company, wanted, first, even
Interpretation:
Cluster 2 centers on:
- Entry-level experiences
- Accounting and finance roles
- First job reflections
- Company fit concerns
Many posts reflect uncertainty or frustration about early career positions.
Cluster 3 — Cybersecurity Career Questions
Top Words: cyber, security, information, web, analyst, entry-levell
Interpretation:
An extremely distinct niche cluster focused on:
- Cybersecurity
- Web security
- Information security certifications
- Entry-level SOC/analyst roles
This cluster clearly captures a specialized career path.
Cluster 4 — Job Offers & Onboarding Decisions
Top Words: company, start, offer, accepted, move, sign-on, new
Interpretation:
Cluster 4 includes posts about:
- Accepting or negotiating job offers
- Start dates
- Relocation
- Signing bonuses
These posts revolve around “I got an offer — should I accept it?” themes.
Summary of Findings
1. Clear latent themes exist
Even with noisy real-world text and limited context, unsupervised clustering successfully surfaced: - A large general-purpose job discussion cluster - Smaller domain-specific clusters (cybersecurity, accounting, HR issues, offer negotiation)
2. Most posts fall into one dominant cluster
Cluster 0 accounts for the majority of posts, indicating the dataset contains a highly mixed but broadly similar vocabulary.
3. Specialized topics form distinct clusters
Cybersecurity (Cluster 3), offer negotiation (Cluster 4), and HR policy issues (Cluster 1) stand out with clearer boundaries.
4. PCA suggests meaningful structure
Despite being only a 2D projection, PCA retains enough variance to show distinct outliers corresponding to smaller clusters.
Summary
Answer to ML Question
Q1: Can we predict high engagement posts?
Yes, with moderate success. Our Logistic Regression model achieves an AUC of 0.665, indicating it can distinguish between high and low engagement posts better than random guessing. The model identifies that:
- Text content (captured by TF-IDF features) is the strongest predictor of engagement
- Post timing (
hour_of_day) has a secondary influence - Text length provides additional signal
Q2: Can early engagement predict final popularity?
Yes, strongly. Early engagement metrics—especially the average comment score in the first hour—are powerful predictors of long-term popularity. Our Gradient Boosted Trees model explains nearly 50% of variance (R² = 0.4952) in final scores, demonstrating that:
- Quality of early discussion matters more than quantity
- First-hour engagement is a critical window for predicting viral potential
- Post content characteristics (title/body length) play supporting roles
Q3: Can We Group Posts into Natural Clusters?
Yes — we can group Reddit posts into meaningful natural clusters using TF-IDF + KMeans. Clusters reflect real semantic themes: general job help, HR issues, accounting careers, cybersecurity, and job offers.
While most posts cluster into one large group, the smaller clusters show the model’s ability to capture niche discussions without supervision.
Cross-Model Insights
Together, the three analyses reveal complementary dynamics behind Reddit post performance:
- Content quality (Q8 TF-IDF features) determines the baseline engagement potential
- Early user reactions (Q9 regression model) amplify or suppress that baseline
- Topical structure (Q10 clustering) shows that engagement potential varies by theme—for example, job-offer posts and cybersecurity discussions show clearer topical cohesion than general job rants
- Overall, popularity follows a two-stage process: content quality → early community response → theme-specific amplification patterns
Business Implications
For Content Creators:
- High-quality writing matters most—textual features dominate initial engagement (Q8)
- Themes identified in Q10 can guide strategy: offer-negotiation posts and niche career paths tend to generate more targeted discussion
- Monitor early comment quality as a success signal (Q9)
For Platform Operators:
- Use Q10 cluster labels for topic-aware ranking, highlighting posts in high-value themes (e.g., career transitions, cybersecurity)
- Build early detection systems that combine Q9’s early metrics with Q10’s topic categories for more accurate viral-post prediction
- Topic clusters help allocate moderation resources where user frustration or HR-related issues are concentrated
For Advertisers/Marketers:
- Cluster-specific targeting becomes possible:
- Cybersecurity cluster → tech training ads
- Job-offer cluster → relocation/HR services
- Early-career cluster → coaching or certification programs
- Cybersecurity cluster → tech training ads
- Combine Q10 topic segments with Q9 early-engagement signals to optimize placement timing and relevance
Limitations:
- Classification model (Q8) trained on a 1% sample; using the full dataset may improve generalization
- Regression model (Q9) excludes posts with no early comments
- Topic clusters (Q10) rely on TF-IDF; using contextual embeddings (e.g., Sentence-BERT) may yield more coherent themes
- Cluster sizes are imbalanced—large general-topic clusters may obscure finer-grained distinctions
- Temporal patterns (posting hour, weekday effects) were not integrated across all models
All ML code is in code/ml/ directory. Models saved in code/ml/models/.