Skip to content
Competition - employee turnover
  • AI Chat
  • Code
  • Report
  • Can you help reduce employee turnover?

    📖 Background

    You work for the human capital department of a large corporation. The Board is worried about the relatively high turnover, and your team must look into ways to reduce the number of employees leaving the company.

    The team needs to understand better the situation, which employees are more likely to leave, and why. Once it is clear what variables impact employee churn, you can present your findings along with your ideas on how to attack the problem.

    💾 The data

    The department has assembled data on almost 10,000 employees. The team used information from exit interviews, performance reviews, and employee records.

    • "department" - the department the employee belongs to.
    • "promoted" - 1 if the employee was promoted in the previous 24 months, 0 otherwise.
    • "review" - the composite score the employee received in their last evaluation.
    • "projects" - how many projects the employee is involved in.
    • "salary" - for confidentiality reasons, salary comes in three tiers: low, medium, high.
    • "tenure" - how many years the employee has been at the company.
    • "satisfaction" - a measure of employee satisfaction from surveys.
    • "avg_hrs_month" - the average hours the employee worked in a month.
    • "left" - "yes" if the employee ended up leaving, "no" otherwise.
    import pandas as pd
    df_origin = pd.read_csv('./data/employee_churn_data.csv')
    df = df_origin.copy()
    departments = df['department'].unique()
    print("Departments: ")

    💪 Competition challenge

    Create a report that covers the following:

    1. Which department has the highest employee turnover? Which one has the lowest?
    2. Investigate which variables seem to be better predictors of employee departure.
    3. What recommendations would you make regarding ways to reduce employee turnover?

    Cleanup data to make categories

    Which department has the highest employee turnover?

    department_turnover_mean = df.groupby(['department']).mean()
    max_turnover_condition = department_turnover_mean["left"] == department_turnover_mean["left"].max()
    max_proportional_turnover = department_turnover_mean[max_turnover_condition]
    highest_turnover_department = departments[max_proportional_turnover.index[0]-1]
    print("The department with lowest highest is: " + highest_turnover_department)

    Which one has the lowest?

    min_turnover_condition = department_turnover_mean["left"] == department_turnover_mean["left"].min()
    min_proportional_turnover = department_turnover_mean[min_turnover_condition]
    lowest_turnover_department = departments[min_proportional_turnover.index[0]-1]
    print("The department with lowest turnover is: " + lowest_turnover_department)

    Investigate which variables seem to be better predictors of employee departure.

    from sklearn.model_selection import train_test_split
    y = df['left']
    df.drop(['left'], axis=1, inplace=True)
    features = df.columns
    from xgboost import XGBRegressor
    def get_model():
        model = XGBRegressor(n_estimators=500, learning_rate=0.03, n_jobs=6)
        return model
    def get_cat_columns(X):
        # "Cardinality" means the number of unique values in a column
        # Select categorical columns with relatively low cardinality (convenient but arbitrary)
        categorical_cols = [cname for cname in X.columns if
                            #X_train_full[cname].nunique() < 10 and 
                            X[cname].dtype == "object"]
        return categorical_cols
    def get_num_columns(X):
        # Select numerical columns
        numerical_cols = [cname for cname in X.columns if 
                        X[cname].dtype in ['int64', 'float64']]
        # Keep selected columns only
        return numerical_cols