image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

import statsmodels.api as sm

df = pd.read_csv('../input/multipleChoiceResponses.csv', encoding='ISO-8859-1')

df = df[['CompensationAmount', 'Age']]

df['CompensationAmount'] = df['CompensationAmount'].str.replace('[^\\w\\s]', '')
df['CompensationAmount'].fillna(0, inplace=True)
df['Age'].fillna(0, inplace=True)
df['CompensationAmount'] = pd.to_numeric(df['CompensationAmount'])
df = df[df['CompensationAmount'] > 0]

y = df['CompensationAmount']
x = df['Age']
x = sm.add_constant(x)
model = sm.GLM(y, x, family=sm.families.Poisson()).fit()

model_g = sm.OLS(y, x).fit()
model_leverage = model_g.get_influence().hat_matrix_diag
model_cooks = model_g.get_influence().cooks_distance[0]
sns.regplot(model_leverage, model_cooks, fit_reg=False)
plt.xlim(xmin=-0.005, xmax=0.02)
plt.xlabel('Leverage')
plt.ylabel("Cook's distance")
plt.title("Cook's vs Leverage")