<jupyter_start><jupyter_text>Employee Churn Analysis  What is Employee Churn ?When an employee leaves the organization is known as churn. Employee churn will be affected by age, tenure, pay, job satisfaction, salary, working conditions, growth potential and employee’s perceptions of fairness. Some other variables such as age, gender, ethnicity, education, and marital status, were essential factors in the prediction of employee churn. Predicting the employee churn will help some proactive measures to be taken for employee recruitment and prevention.For the given HR dataset, Do the Employee Churn Analysis  About the attributes of the dataset - HR.csv1. satisfaction_level: It is employee satisfaction point, which ranges from 0-1.2. last_evaluation: It is evaluated performance by the employer, which also ranges from 0-1.3. number_projects: How many numbers of projects assigned to an employee?4. average_monthly_hours: How many average numbers of hours worked by an employee in a month?5. time_spent_company: time_spent_company means employee experience. The number of years spent by an employee in the company.6. work_accident: Whether an employee has had a work accident or not.7. promotion_last_5years: Whether an employee has had a promotion in the last 5 years or not.8. Departments: Employee's working department/division.  Stmt: Find out the Pattern of Employee churn and Predict the future churn. Hints:1. Filter out the employees who has left2. Find out the minimum 3 group of employees based on satisfaction level and the evaluation of the employee3. Group 1 : high satisfaction and high evalation   Group 2: Low satisfaction and high Evaluation   Group 3: moderate satisfaction and moderate evaluation4. Find out how many in each category fits on to 3 groups.5. Filter out the employees who has not left6. Predict how many employees in the organization may leave according to the pattern modelled earlier with 3 groups<jupyter_code>import numpy as np
import pandas as pd
df=pd.read_csv('C:/Users/mozhi/Desktop/DA 2019/Assessment/ISA2/HR.csv')
df.head()
#import module
from sklearn.cluster import KMeans
# Filter data
left_emp =  df[['satisfaction_level', 'last_evaluation']][df.left == 1]
# Create groups using K-means clustering.
kmeans = KMeans(n_clusters = 3, random_state = 0).fit(left_emp)
# Add new column "label" annd assign cluster labels.
import matplotlib.pyplot as plt
left_emp['label'] = kmeans.labels_
# Draw scatter plot
plt.scatter(left_emp['satisfaction_level'], left_emp['last_evaluation'], c=left_emp['label'])
plt.xlabel('Satisfaction Level')
plt.ylabel('Last Evaluation')
plt.title('3 Clusters of employees who left')
plt.show()
left_emp['label'].value_counts()
about_to_leave =  df[['satisfaction_level', 'last_evaluation']][df.left == 0]
clus=kmeans.predict(about_to_leave)
clus
about_to_leave['labels']=clus
about_to_leave.head()
about_to_leave['labels'].value_counts()
# Draw scatter plot
plt.scatter(about_to_leave['satisfaction_level'], about_to_leave['last_evaluation'], c=about_to_leave['labels'])
plt.xlabel('Satisfaction Level')
plt.ylabel('Last Evaluation')
plt.title('3 Clusters of employees who is about_to_leave')
plt.show()
#Conclusion: 32 % may leave the organization<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07718327183271832, 'fraction_numerical': 0.011992619926199263, 'mean_word_length': 5.921276595744681, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '178467', 'license': 'MIT', 'n_tokens_mistral': 951, 'n_tokens_neox': 870, 'n_words': 380, 'path': 'Sem4/DataAnalytics/DA Lab - students copy/Clustering/ISA2-Lab solution.ipynb', 'repo_name': 'nsudhanva/mca-code', 'size': '3252'}