CoolFace
Modelpublic

razsarusi/stackoverflow-salary-prediction

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
Model Card

Stack Overflow Salary Prediction - Developer Survey 2024

๐ŸŽฌ Project Demo

Watch the demo video here

๐Ÿ“บ A 6-minute walkthrough covering the entire project: data exploration, feature engineering, model training, and key insights.

๐Ÿ“Š Project Overview

This project predicts annual developer compensation (salary) based on factors like experience, location, technologies, education, and AI tool adoption.

The data comes from the Stack Overflow Annual Developer Survey 2024, covering 65,437 developers worldwide.

๐ŸŽฏ Objectives

  1. 1.Regression: Predict exact salary in USD
  2. 2.Classification: Categorize developers into salary tiers (Low/Medium/High)
  3. 3.Clustering: Discover natural developer segments

๐Ÿ“ Dataset

  • โ€”Source: Stack Overflow Annual Developer Survey 2024
  • โ€”Size: 65,437 rows ร— 114 columns (raw)
  • โ€”After cleaning: 22,765 rows ร— 68 features
  • โ€”Target: ConvertedCompYearly (USD)
  • โ€”Available on Kaggle: <https://www.kaggle.com/datasets/berkayalan/stack-overflow-annual-developer-survey-2024>

๐Ÿ” Key Findings (EDA)

Target Variable Analysis

  • โ€”23,435 valid salary responses (35.8% of dataset)
  • โ€”Highly right-skewed distribution
  • โ€”Range: $1 to $16,256,603 (extreme outliers exist)
  • โ€”Median salary: $65,000
  • โ€”Mean salary: $86,155
  • โ€”97.1% in realistic range ($1K-$500K)
  • โ€”Decision: Apply log transformation + filter outliers

[image]

Salary distribution showing extreme right-skewness and the value of log transformation for modeling.

Data Structure

  • โ€”100 categorical (object) columns
  • โ€”13 float columns
  • โ€”1 integer column (ResponseId)
  • โ€”Most predictive features need conversion from text to numeric

Top Paying Countries (by median salary)

RankCountryMedian SalarySample Size
1USA$141,0004,596
2Israel$113,334217
3Switzerland$111,417385
4Australia$95,796505
5Ireland$91,295120
6Denmark$88,993211
7Canada$87,231861
8UK$84,0381,376

Key insight: Geographic location is the most powerful predictor of salary. The same role can earn 5-10x more in the US/Israel/Switzerland compared to emerging economies.

Geographic Salary Variance

Boxplot analysis revealed:

  • โ€”USA: Median $140K with high variance ($100K-$200K interquartile range), many high-end outliers reaching $500K+
  • โ€”Western Europe (Germany, UK): Median $70-85K, moderate variance
  • โ€”Eastern Europe (Poland, Ukraine): Median $35-55K, but with significant high-end outliers (likely remote workers for foreign companies)
  • โ€”Emerging markets (India, Brazil): Median $15-25K, low variance
  • โ€”Salary range from highest to lowest country median: ~10x difference

[image]

Salary distributions across the top 10 countries (by sample size). USA dominates both in median salary and variance.

Top Paying Developer Roles

RankRoleMedian Salary
1Senior Executive (C-Suite, VP)$120K
2Engineering Manager$115K
3Engineer, Site Reliability (SRE)$98K
4Cloud Infrastructure Engineer$96K
5Security Professional$80K
6Data Engineer$77K
7Developer, AI$75K
8Data Scientist / ML Specialist$73K
9Back-end Developer$68K
10Full-stack Developer$64K

Key insights:

  • โ€”Specialization pays: Infrastructure roles (SRE, Cloud) earn 30-50% more than general development roles
  • โ€”Management track: Engineering managers and executives top the list
  • โ€”Counter-intuitive finding: AI Developer ranks 7th, not at top despite the AI hype - market still developing
  • โ€”Full-stack paradox: Largest group (18,260 respondents) but lowest median in top-15, suggesting market saturation

[image]

Top 15 developer roles ranked by median salary. Note how specialized infrastructure roles (SRE, Cloud) outperform general development roles.

Experience vs Salary Relationship

  • โ€”Overall correlation: 0.38 (moderate, due to country variance)
  • โ€”Career growth pattern observed:
  • โ€”Years 0-10: Steep growth ($25K โ†’ $78K, 3x increase)
  • โ€”Years 10-20: Continued growth ($78K โ†’ $95K)
  • โ€”Years 20+: Plateau effect (~$100-110K, role-dependent)
  • โ€”Within-country correlation is much stronger than overall correlation
  • โ€”Median professional experience in dataset: 8 years

[image]

The career growth curve: rapid early growth followed by plateau effect after ~20 years.

Country-Experience Interaction (Simpson's Paradox)

Within-country correlations between experience and salary:

  • โ€”Germany: 0.438 (highest - structured market)
  • โ€”India: 0.394 (experience matters)
  • โ€”USA: 0.319 (role/company matter more)
  • โ€”UK: 0.271
  • โ€”Canada: 0.299

Insight: The same career trajectory yields vastly different outcomes based on geography. A junior developer in USA ($65K) earns more than a senior developer in India ($45K after 25 years). This makes country a critical feature for the model.

[image]

The "geography is destiny" effect: same experience yields drastically different salaries across countries.

Technology Indicators (Linear Correlation with Salary)

TechnologyUsers%Correlation
AWS9,89443.5%+0.139
Go3,38814.9%+0.087
Rust2,85312.5%+0.082
Copilot8,20336.0%+0.060
Scala6692.9%+0.058
Azure5,82525.6%+0.047
Python11,14248.9%+0.044
Kubernetes4,18018.4%-0.004
Docker11,59150.9%-0.002
ChatGPT14,82765.1%-0.102

Insights:

  • โ€”AWS is the strongest single technology indicator - likely because AWS adoption correlates with established tech companies in higher-paying countries
  • โ€”Docker, Kubernetes, Terraform show ~0 linear correlation despite being valuable skills - they have become industry standards (commoditized)
  • โ€”ChatGPT usage is negatively correlated - consistent with junior developers relying more on AI tools than senior engineers
  • โ€”These features still provide value through non-linear interactions in tree-based models (Random Forest, XGBoost)

Key Predictive Features Identified

  • โ€”YearsCodePro - Years of professional coding experience
  • โ€”Country - Geographic location (massive impact)
  • โ€”EdLevel - Education level (8 ordered categories)
  • โ€”DevType - Developer role type (34 categories - needs grouping)
  • โ€”OrgSize - Company size (10 ordered categories)
  • โ€”RemoteWork - Remote/Hybrid/In-person

๐Ÿ› ๏ธ Methodology

Data Preprocessing

  • โ€”Filtered rows with valid salary data (65,437 โ†’ 22,765 after outlier removal)
  • โ€”Removed extreme outliers (<$1K and >$500K)
  • โ€”Applied log transformation to target (handles right-skewed distribution)
  • โ€”Converted text-based numeric columns (YearsCode, YearsCodePro)
  • โ€”Median imputation for missing experience values

Feature Engineering

  • โ€”Ordinal Encoding: EdLevel (8 levels), OrgSize (10 sizes), Age (8 groups)
  • โ€”Country Grouping: 185 countries โ†’ 11 regions based on geography and economy
  • โ€”DevType Grouping: 34 roles โ†’ 7 broader categories
  • โ€”Multi-select handling:
  • โ€”Created 5 binary indicators for Employment status
  • โ€”Count features for technologies (numlanguages, numdatabases, etc.)
  • โ€”Binary flags for high-value technologies (usesAWS, usesPython, etc.)
  • โ€”One-Hot Encoding: Applied to Region, DevCategory, RemoteWork, Industry
  • โ€”Final dataset: 22,765 samples ร— 68 features

Models Trained

  • โ€”Regression: Linear Regression, Random Forest, XGBoost
  • โ€”Classification: Logistic Regression, Random Forest, XGBoost
  • โ€”Clustering: K-Means with K=4 (chosen via Silhouette analysis)

๐Ÿ“ˆ Results

Regression Model Performance

ModelRยฒ (log)Rยฒ ($)MAE ($)RMSE ($)Training Time
Linear Regression0.53190.433330,91749,592<1s
Random Forest0.56980.512128,00546,01830s
XGBoost (best)0.58400.532627,51345,0392.6s

Best Model: XGBoost with Rยฒ = 0.5326 (explains 53% of salary variance)

Feature Importance Analysis

Top features driving predictions (XGBoost): | Rank | Feature | Importance | |------|---------|------------| | 1 | RegionNorthAmerica | 36.58% | | 2 | RegionWesternEurope | 8.89% | | 3 | RegionAsiaDeveloping | 6.86% | | 4 | RegionAsiaPacific_Developed | 4.62% | | 5 | YearsCodePro | 3.28% |

Feature Importance by Category

CategoryTotal Importance
๐ŸŒ Region (Geography)67.0%
๐Ÿ’ป Tech indicators6.9%
โฐ Experience5.7%
๐Ÿญ Industry5.5%
๐Ÿ’ผ Employment status4.9%
๐Ÿข Other3.4%
๐Ÿ’ผ Developer Category3.1%
๐Ÿ“Š Tech counts1.9%
๐Ÿ‘ค Demographics1.6%

Key insight: Geography is the dominant predictor (67%), confirming our EDA finding that location matters more than skills, experience, or role for salary determination. The same developer in different regions can have 5-10x salary differences.

[image]

Top 20 most important features in XGBoost. Region_North_America alone accounts for 36.6% of model decisions.

Classification Model Performance

Salary categorized into 3 classes (33%/33%/33%):

  • โ€”Low: < $46,185
  • โ€”Medium: $46,185 - $91,719
  • โ€”High: > $91,719
ModelAccuracy
Logistic Regression68.72%
Random Forest69.38%
XGBoost (best)70.39%

Best Classifier: XGBoost with 70.39% accuracy (vs 33% baseline)

Per-Class Performance (XGBoost)

CategoryAccuracyPrecisionRecallF1-Score
Low75.77%0.76020.75770.7589
High74.14%0.75950.74140.7503
Medium61.57%0.59990.61570.6077

Key insights:

  • โ€”Model excels at distinguishing extreme categories (Low/High)
  • โ€”Misclassifications between Low โ†” High are rare (~4%)
  • โ€”Medium category is hardest to classify (boundary cases)
  • โ€”Model tends to predict Medium when uncertain (conservative strategy)

[image]

XGBoost confusion matrix. The model rarely confuses Low with High (~4% error rate), but Medium is harder to classify.

Clustering Analysis (K-Means, K=4)

K-Means clustering identified 4 distinct developer personas:

ClusterPersonaSizeMedian SalaryYears ProTop Region
0Mainstream Developer45.1%$58,3756Western Europe
1Junior / Eastern Europe10.2%$42,9626Western/Eastern Europe
2Modern Tech Worker25.1%$66,0007North America
3Elite / Senior19.6%$105,25822North America

Key clustering insights:

  • โ€”ChatGPT usage is inversely correlated with seniority: Cluster 2 (modern) uses it 88% of the time, while Cluster 3 (elite/senior) only 44%
  • โ€”Cluster 3 (Elite) stands out with 22+ years experience, North American location, and high salary - the "veteran developer" persona
  • โ€”Cluster 2 (Modern Tech Worker) represents AI-era developers using all modern tools (TypeScript, AWS, Copilot, ChatGPT) heavily
  • โ€”Silhouette scores are low (~0.04) due to high-dimensional data, but clusters remain interpretable and actionable

[image]

Elbow Method and Silhouette Score analysis used to determine optimal K=4.

[image]

4 developer personas visualized in 2D using PCA. Despite low variance explained (11.7%), the clusters show meaningful separation.

[image]

Salary distributions per cluster reveal the clear hierarchy: Elite/Senior cluster has dramatically higher salaries with tighter distribution.

๐Ÿš€ Usage

Loading the Models

python
import pickle

# Load regression model (predicts salary in USD)
with open('regression_model.pkl', 'rb') as f:
    reg_model = pickle.load(f)

# Load classification model (predicts Low/Medium/High)
with open('classification_model.pkl', 'rb') as f:
    cls_model = pickle.load(f)

# Load clustering model (assigns to 1 of 4 personas)
with open('kmeans_model.pkl', 'rb') as f:
    kmeans_model = pickle.load(f)

# Load preprocessing tools
with open('scaler.pkl', 'rb') as f:
    scaler = pickle.load(f)

with open('label_encoder.pkl', 'rb') as f:
    label_encoder = pickle.load(f)

with open('feature_names.pkl', 'rb') as f:
    feature_names = pickle.load(f)

Making Predictions

python
import numpy as np

# Prepare your features (must match feature_names order)
# X_new must have shape (n_samples, 68)

# Regression prediction (returns log-scale salary)
log_salary_pred = reg_model.predict(X_new)
salary_usd = np.expm1(log_salary_pred)  # Convert back to USD

# Classification prediction
class_pred = cls_model.predict(X_new)
class_label = label_encoder.inverse_transform(class_pred)  # Low/Medium/High

# Clustering (which persona?)
X_scaled = scaler.transform(X_new)
cluster = kmeans_model.predict(X_scaled)

๐Ÿ“š Project Structure

data_science_project/
โ”œโ”€โ”€ StackOverflow_Salary_Prediction.ipynb  # Main notebook with full pipeline
โ”œโ”€โ”€ README.md                                # This file
โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ regression_model.pkl                 # XGBoost regressor (1.2 MB)
โ”‚   โ”œโ”€โ”€ classification_model.pkl             # XGBoost classifier (3.3 MB)
โ”‚   โ”œโ”€โ”€ kmeans_model.pkl                     # K-Means cluster model (92 KB)
โ”‚   โ”œโ”€โ”€ scaler.pkl                           # StandardScaler for preprocessing
โ”‚   โ”œโ”€โ”€ label_encoder.pkl                    # LabelEncoder for class names
โ”‚   โ””โ”€โ”€ feature_names.pkl                    # List of 68 feature names
โ””โ”€โ”€ images/
    โ”œโ”€โ”€ 01_salary_distribution.png           # Target variable analysis
    โ”œโ”€โ”€ 02_salary_by_country.png             # Country-level boxplot
    โ”œโ”€โ”€ 03_top_developer_roles.png           # Roles ranked by salary
    โ”œโ”€โ”€ 04_salary_vs_experience.png          # Career growth curve
    โ”œโ”€โ”€ 05_experience_by_country.png         # Country comparison
    โ”œโ”€โ”€ 06_feature_importance.png            # XGBoost top features
    โ”œโ”€โ”€ 07_confusion_matrix.png              # Classification results
    โ”œโ”€โ”€ 08_elbow_method.png                  # Optimal K selection
    โ”œโ”€โ”€ 09_clusters_pca.png                  # 2D cluster visualization
    โ””โ”€โ”€ 10_salary_by_cluster.png             # Salary per persona

๐Ÿ‘ค Author

Raz Sarusi

Data Science Course Project - Assignment #2

๐Ÿ“… Date

Project completed: May 2026