![[shutterstock_2480361723.jpg|491]] Divorce is influenced by a combination of demographic, socioeconomic, and relationship behavioral factors. While traditional statistical analyses identify factors associated with divorce, modern machine learning models can capture complex nonlinear relationships and interactions to improve predictive performance. In this project, I built an end-to-end machine learning pipeline to predict whether a marriage would end in divorce. Beyond prediction accuracy, I also focused on **model interpretability** using SHAP (SHapley Additive exPlanations) to understand the key drivers behind divorce risk. # Dataset The dataset contains demographic information, financial characteristics, and relationship behavior measurements collected from married couples. ### Target Variable - **divorced** - `1`: Marriage ended in divorce - `0`: Marriage remained intact ### Features The dataset includes variables from several domains: ### Demographics - Marriage number - Age at marriage - Age gap - Education level - Household income ### Family Characteristics - Number of children - Child before marriage - Cohabitation before marriage ### Employment & Financial Factors - Both partners employed - Financial stress ### Relationship Behaviors (Gottman Framework) - Criticism - Contempt - Defensiveness - Stonewalling - Repair attempt success - Positive-to-negative interaction ratio - Conflict frequency - Shared activities Several of these behavioral variables originate from **John Gottman's research**, which identifies communication patterns that strongly predict relationship success or failure. # Project Workflow ## 1. Exploratory Data Analysis I first explored the dataset by: - inspecting missing values - checking distributions - identifying outliers - analyzing feature correlations - comparing divorce rates across categorical variables This step helped identify potential data quality issues and understand which variables were likely to be predictive. ## 2. Feature Engineering To improve model performance, I applied several preprocessing techniques. ### Ordinal Encoding Categorical variables with natural ordering were converted into numerical values, including: - Education level - Religious attendance ### Log Transformation Highly skewed numerical features were log-transformed, including: - Age at marriage - Household income - Contempt - Positive-to-negative interaction ratio - Years married This reduced skewness and improved numerical stability. ### Standardization Continuous numerical variables were standardized using `StandardScaler`, while binary variables remained unchanged. ### Pipeline All preprocessing steps were implemented using a **Scikit-learn Pipeline** and **ColumnTransformer**, allowing preprocessing and model training to be performed together without data leakage. # Baseline Model The initial baseline model was Logistic Regression. Performance: | Metric | Value | | --------- | --------- | | Accuracy | **0.780** | | Precision | **0.766** | | Recall | **0.750** | | F1 Score | **0.758** | | ROC-AUC | **0.861** | These results indicated that even a simple linear model performed well on the dataset. # Hyperparameter Tuning I optimized Logistic Regression using GridSearchCV. The best model selected: - L2 regularization - Optimal regularization strength (C) - 5-fold cross-validation - ROC-AUC optimization # Threshold Optimization Instead of using the default classification threshold of **0.5**, I searched across multiple thresholds to maximize the F1 score. ![[Screenshot 2026-08-12 at 4.09.04 PM.png|329]] The optimal threshold was: **0.35** Performance at this threshold: | Metric | Value | | --------- | --------- | | Precision | **0.693** | | Recall | **0.863** | | F1 Score | **0.769** | Lowering the threshold substantially increased recall, making the model better at identifying marriages at risk of divorce while maintaining a reasonable precision. # Model Comparison I compared several machine learning algorithms using the exact same preprocessing pipeline. | Model | Accuracy | Precision | Recall | F1 | ROC-AUC | | ------------------- | --------: | --------: | --------: | --------: | --------: | | **XGBoost** | **0.788** | 0.770 | **0.768** | **0.769** | 0.868 | | **CatBoost** | 0.787 | **0.770** | 0.765 | 0.767 | **0.870** | | **LightGBM** | 0.785 | 0.768 | 0.764 | 0.766 | 0.867 | | Logistic Regression | 0.780 | 0.766 | 0.750 | 0.758 | 0.861 | | Random Forest | 0.777 | 0.760 | 0.752 | 0.756 | 0.856 | ## Key Observation Tree-based boosting models consistently outperformed Logistic Regression, although the improvement was relatively modest. This suggests that most relationships in the data are already captured reasonably well by a linear model, with boosted trees providing additional gains by modeling nonlinear effects and feature interactions. # Explainable Features with SHAP To understand **why** the model made its predictions, I used **SHAP (SHapley Additive exPlanations)** with the CatBoost model. Unlike traditional feature importance, SHAP explains: - how much each feature contributes to an individual prediction - whether a feature increases or decreases divorce risk - nonlinear effects - interactions between variables This makes the model transparent rather than a black box. ![[Screenshot 2026-08-12 at 4.10.10 PM.png|484]] # Key Findings ## 1. Relationship behaviors dominate prediction The strongest predictors were not demographic characteristics but relationship behaviors. The model consistently identified: - higher contempt - higher criticism - lower repair attempt success - lower positive-to-negative interaction ratio as major contributors to increased divorce risk and present roughly linear relationship with divorce risk. This aligns closely with decades of relationship psychology research. ## 2. Marriage duration has a strong nonlinear effect The SHAP dependence plot showed that divorce risk decreases as marriages become longer. The model suggests three approximate stages: - Marriages lasting **less than approximately 4–6 years** are associated with the highest predicted divorce risk. - Around **8–9 years**, the model reaches a turning point where additional years of marriage begin to reduce the predicted probability of divorce rapidly. Overall, the model suggests that marriage stability increases substantially during the first decade of marriage, with the largest improvement occurring between approximately **8 and 15 years**. ![[Screenshot 2026-08-12 at 4.35.13 PM.png|311]] ## 3. Early 30s marriage substantially reduce divorce risk The SHAP dependence plot reveals a strong nonlinear relationship between age at marriage and predicted divorce risk. Key observations include: - Marrying before approximately **26 years old** is associated with a noticeably higher predicted probability of divorce. - Around **29 years old**, the model reaches a turning point where the contribution to divorce risk changes from positive to negative. - After **30 to 35 years old**, the predicted divorce risk declines rapidly with aging when marriage. Overall, the model suggests that delaying marriage into the early 30s substantially reduces predicted divorce risk. ![[Screenshot 2026-08-12 at 4.44.49 PM.png|314]] ## 4. Mid and upper-mid household income reduce divorce risk The SHAP dependence plot indicates a clear nonlinear relationship between household income and predicted divorce risk. Key observations include: - Household incomes below approximately **\$60,000** are associated with higher predicted divorce risk. - The largest reduction in predicted divorce risk occurs between approximately **\$100,000 and \$160,000**. - Above approximately **\$250,000**, the protective effect begins to plateau, indicating diminishing returns from additional household income. Overall, the model suggests that financial stability is associated with lower predicted divorce risk, with the greatest improvement occurring as household income rises into the middle- and upper-middle-income range. ![[Screenshot 2026-08-12 at 4.46.41 PM.png|310]] ## 5. Evaluating potential target leakage Because `years_married` is measured up to the divorce event (or current date for ongoing marriages), it may introduce target leakage if the goal is to predict divorce early in a marriage. To investigate this, I retrained the model after removing both: - `years_married` - `years_to_divorce` Performance changed as follows: | Metric | With Years Married | Without Years Married | | --------- | -----------------: | --------------------: | | Accuracy | 0.780 | 0.750 | | Precision | 0.766 | 0.734 | | Recall | 0.750 | 0.716 | | F1 | 0.758 | 0.725 | | ROC-AUC | 0.861 | 0.834 | Although performance decreased slightly, the model still achieved a **ROC-AUC of 0.834**, indicating that the remaining demographic and behavioral features retained substantial predictive power. This suggests that while marriage duration is informative, the model is **not solely dependent on it**, and relationship behaviors remain strong independent predictors of divorce. # Conclusion This project demonstrates how modern machine learning can be used to understand the factors associated with divorce. Key takeaways include: - Relationship behaviors are stronger predictors than demographic characteristics. - Divorce risk is highest during the first **4-6 years** of marriage, begins declining around **8-9 years** rapidly. - Marrying before **26 years old** is associated with higher divorce risk while **30s** marriage substantially present decreasing divorce. - Low household income below **$60,000** has highest divorce risk, mid to upper-mid income **$100,000 to $160,000** shows rapid decreasing rate of divorce. There is no significant marginal effect after passing **$250,000** Overall, the results suggest that divorce risk is influenced by a combination of **relationship quality, life stage, and financial stability**, with clear nonlinear thresholds rather than simple linear trends. These findings illustrate how predictive models can move beyond "which variables matter" to reveal **when** risk changes most dramatically, providing insights that are both statistically informative and practically interpretable.