0% found this document useful (0 votes)
31 views19 pages

Chapter 1

The document discusses predicting employee churn using HR analytics and Python. It introduces HR analytics and describes a dataset containing employee records and attributes like satisfaction, evaluation, salary, etc. It demonstrates preprocessing the categorical variables, calculating descriptive statistics like turnover rates, and correlation between variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views19 pages

Chapter 1

The document discusses predicting employee churn using HR analytics and Python. It introduces HR analytics and describes a dataset containing employee records and attributes like satisfaction, evaluation, salary, etc. It demonstrates preprocessing the categorical variables, calculating descriptive statistics like turnover rates, and correlation between variables.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Introduction to HR

analytics
H R A N A LY T I C S : P R E D I C T I N G E M P L OY E E C H U R N I N P Y T H O N

Hrant Davtyan
Assistant Professor of Data Science
American University of Armenia
What is HR analytics?
Also known as People analytics

Is a data-driven approach to managing people at work.

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Problems addressed by HR analytics
Hiring/Assessment Learning and Development

Retention Collaboration/team composition

Performance evaluation Other (e.g. absenteeism)

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Employee turnover
Employee turnover is the process of employees leaving the company

Also known as employee a rition or employee churn

May result in high costs for the company

May a ect company's hiring or retention decisions

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Course structure
1. Describing and manipulating the dataset

2. Predicting employee turnover

3. Evaluating and tuning prediction

4. Selection nal model

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


import pandas as pd
data = pd.read_csv("turnover.csv")
data.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 14999 entries, 0 to 14998
Data columns (total 10 columns):
satisfaction_level 14999 non-null float64
last_evaluation 14999 non-null float64
number_project 14999 non-null int64
average_montly_hours 14999 non-null int64
time_spend_company 14999 non-null int64
work_accident 14999 non-null int64
churn 14999 non-null int64
promotion_last_5years 14999 non-null int64
department 14999 non-null object
salary 14999 non-null object
dtypes: float64(2), int64(6), object(2)
memory usage: 1.1+ MB

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


The dataset
data.head()

satisfaction evaluation number_of_projects ... promotion department salary


0 0.38 0.53 2 ... 0 sales low
1 0.80 0.86 5 ... 0 sales medium
2 0.11 0.88 7 ... 0 sales medium
3 0.72 0.87 5 ... 0 sales low
4 0.37 0.52 2 ... 0 sales low

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Unique values
print(data.salary.unique())

array(['low', 'medium', 'high'], dtype=object)

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Let's practice!
H R A N A LY T I C S : P R E D I C T I N G E M P L OY E E C H U R N I N P Y T H O N
Transforming
categorical
variables
H R A N A LY T I C S : P R E D I C T I N G E M P L OY E E C H U R N I N P Y T H O N

Hrant Davtyan
Assistant Professor of Data Science
American University of Armenia
Types of categorical variables
Ordinal - variables with two or more categories that can be ranked or ordered
Our example: salary

Values: low, medium, high

Nominal - variables with two or more categories with do not have an intrinsic order
Our example: department

Values: sales, accounting, hr, technical, support, management, IT, product_mng,


marketing, RandD

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Encoding categories (salary)
# Change the type of the "salary" column to categorical
data.salary = data.salary.astype('category')
# Provide the correct order of categories
data.salary = data.salary.cat.reorder_categories(['low',
'medium',
'high'])
# Encode categories with integer values
data.salary = data.salary.cat.codes

Old values New values


low 0
medium 1
high 2

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Getting dummies
# Get dummies and save them inside a new DataFrame
departments = pd.get_dummies(data.department)

Example output:

IT RandD accounting hr management marketing product_mng sales support technical


0 0 0 0 0 0 0 0 0 0 1

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Dummy trap
departments.head()

IT RandD accounting hr management marketing product_mng sales support technical


0 0 0 0 0 0 0 0 0 0 1

departments = departments.drop("technical", axis = 1)


departments.head()

IT RandD accounting hr management marketing product_mng sales support


0 0 0 0 0 0 0 0 0 0

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Let's practice!
H R A N A LY T I C S : P R E D I C T I N G E M P L OY E E C H U R N I N P Y T H O N
Descriptive statistics
H R A N A LY T I C S : P R E D I C T I N G E M P L OY E E C H U R N I N P Y T H O N

Hrant Davtyan
Assistant Professor of Data Science
American University of Armenia
Turnover rate
# Get the total number of observations and save it
n_employees = len(data)
# Print the number of employees who left/stayed
print(data.churn.value_counts())
# Print the percentage of employees who left/stayed
print(data.churn.value_counts()/n_employees*100)

0 76.191746
1 23.808254
Name: churn, dtype: float64

Summary

Stayed Le
76.19% 23.81%

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Correlations
import matplotlib.pyplot as plt
import seaborn as sns
corr_matrix = data.corr()
sns.heatmap(corr_matrix)
plt.show()

HR ANALYTICS: PREDICTING EMPLOYEE CHURN IN PYTHON


Let's practice!
H R A N A LY T I C S : P R E D I C T I N G E M P L OY E E C H U R N I N P Y T H O N

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy