Divorce Predictors
import os,re,zipfile
import pandas as pd
import numpy as np
from types import SimpleNamespace
from matplotlib import pyplot as plt
plt.style.use('dark_background')
plt.style.use('seaborn')
- If one of us apologizes when our discussion deteriorates, the discussion ends.
- I know we can ignore our differences, even if things get hard sometimes.
- When we need it, we can take our discussions with my spouse from the beginning and correct it.
- When I discuss with my spouse, to contact him will eventually work.
- The time I spent with my wife is special for us.
- We don't have time at home as partners.
- We are like two strangers who share the same environment at home rather than family.
- I enjoy our holidays with my wife.
- I enjoy traveling with my wife.
- Most of our goals are common to my spouse.
- I think that one day in the future, when I look back, I see that my spouse and I have been in harmony with each other.
- My spouse and I have similar values in terms of personal freedom.
- My spouse and I have similar sense of entertainment.
- Most of our goals for people (children, friends, etc.) are the same.
- Our dreams with my spouse are similar and harmonious.
- We're compatible with my spouse about what love should be.
- We share the same views about being happy in our life with my spouse
- My spouse and I have similar ideas about how marriage should be
- My spouse and I have similar ideas about how roles should be in marriage
- My spouse and I have similar values in trust.
- I know exactly what my wife likes.
- I know how my spouse wants to be taken care of when she/he sick.
- I know my spouse's favorite food.
- I can tell you what kind of stress my spouse is facing in her/his life.
- I have knowledge of my spouse's inner world.
- I know my spouse's basic anxieties.
- I know what my spouse's current sources of stress are.
- I know my spouse's hopes and wishes.
- I know my spouse very well.
- I know my spouse's friends and their social relationships.
- I feel aggressive when I argue with my spouse.
- When discussing with my spouse, I usually use expressions such as ‘you always’ or ‘you never’ .
- I can use negative statements about my spouse's personality during our discussions.
- I can use offensive expressions during our discussions.
- I can insult my spouse during our discussions.
- I can be humiliating when we discussions.
- My discussion with my spouse is not calm.
- I hate my spouse's way of open a subject.
- Our discussions often occur suddenly.
- We're just starting a discussion before I know what's going on.
- When I talk to my spouse about something, my calm suddenly breaks.
- When I argue with my spouse, ı only go out and I don't say a word.
- I mostly stay silent to calm the environment a little bit.
- Sometimes I think it's good for me to leave home for a while.
- I'd rather stay silent than discuss with my spouse.
- Even if I'm right in the discussion, I stay silent to hurt my spouse.
- When I discuss with my spouse, I stay silent because I am afraid of not being able to control my anger.
- I feel right in our discussions.
- I have nothing to do with what I've been accused of.
- I'm not actually the one who's guilty about what I'm accused of.
- I'm not the one who's wrong about problems at home.
- I wouldn't hesitate to tell my spouse about her/his inadequacy.
- When I discuss, I remind my spouse of her/his inadequacy.
- I'm not afraid to tell my spouse about her/his incompetence.
zip_name = 'divorce.csv'
if zip_name not in os.listdir('.'):
!wget https://archive.ics.uci.edu/ml/machine-learning-databases/00497/divorce.rar
!unrar e divorce.rar
os.listdir('.')
df = pd.read_csv('divorce.csv',sep=';')
df
XGBoost + Hyper-Parameters Tuning
import xgboost as xgb
from sklearn.model_selection import GridSearchCV
from sklearn.ensemble import IsolationForest
param_grid = {
"learning_rate" : [0.05, 0.10 ],
"max_depth" : [ 1, 4, 7, 14, 20],
"min_child_weight" : [ 3, 5, 7 ],
"gamma" : [ 0.1, 0.3],
"colsample_bytree" : [ 0.3, 0.5 , 0.7 ],
"n_estimators" : [ 1000 ],
"objective": ['binary:logistic','multi:softmax','multi:softprob'],
"num_class": [df.Class.nunique()]
}
xgc = xgb.XGBClassifier()
grid = GridSearchCV(xgc, param_grid, cv=3,verbose=10,n_jobs=-1)
grid.fit(df[df.columns[:-1]],df['Class'])
Best Hyper-Parameters
for k,v in grid.best_params_.items():
print(f'{k} : {v}')
Feature Importance
After tuning the most important questions are:
- My spouse and I have similar ideas about how marriage should be
- My spouse and I have similar values in trust.
- We're just starting a discussion before I know what's going on.
fig,ax = plt.subplots(1,1,figsize=(7,10))
xgb.plot_importance(grid.best_estimator_,height=.4,ax=ax)
isf = IsolationForest(n_estimators=1000,n_jobs=-1)
anomalies = isf.fit_predict(df)
df['anomalies'] = anomalies
df.anomalies.value_counts().plot.bar(rot=0)
Top 3 Samples with Anomalies
df[df.anomalies == -1][:3]