| | --- |
| | license: apache-2.0 |
| | language: |
| | - en |
| | inference: true |
| | --- |
| | # HR Attrition Model |
| |
|
| | This model predicts the survival function of employees based on various features using a Cox Proportional Hazards model. The model aims to estimate how long an employee is likely to stay at the company based on a variety of factors. |
| |
|
| | ## Model Description |
| |
|
| | The HR Attrition Model leverages the Cox Proportional Hazards method to predict employee retention. Key features used in this model include demographic information, job details, and work-life balance metrics. The model is trained on the "HR_Attrition" dataset and is designed to help HR departments understand employee attrition risks. |
| | |
| | ## Features |
| | |
| | The following features are used for predictions: |
| | - Age |
| | - DistanceFromHome |
| | - Education |
| | - NumCompaniesWorked |
| | - PercentSalaryHike |
| | - TotalWorkingYears |
| | - TrainingTimesLastYear |
| | - WorkLifeBalance |
| | - YearsInCurrentRole |
| | - YearsSinceLastPromotion |
| | - YearsWithCurrManager |
| | - BusinessTravel (Travel_Rarely, Travel_Frequently) |
| | - Department (Research & Development, Sales) |
| | - EducationField (Life Sciences, Medical, Marketing, Other, Technical Degree) |
| | - Gender (Male) |
| | - JobRole (Research Scientist, Sales Executive, Laboratory Technician, Manufacturing Director, Healthcare Representative, Manager, Sales Representative, Research Director) |
| | - MaritalStatus (Married, Single) |
| | - OverTime (Yes) |
| | |
| | ## Usage |
| | |
| | To use this model, you need to load the model and pass the input features in the required format. |
| | |
| | ### Example |
| | |
| | Here is an example of how to use the model to predict the survival function: |
| | |
| | ```python |
| | import joblib |
| | import pandas as pd |
| | |
| | class HRAttritionModel: |
| | def __init__(self, model_path): |
| | self.model = joblib.load(model_path) |
| | self.features = ['Age', 'DistanceFromHome', 'Education', 'NumCompaniesWorked', 'PercentSalaryHike', |
| | 'TotalWorkingYears', 'TrainingTimesLastYear', 'WorkLifeBalance', 'YearsInCurrentRole', |
| | 'YearsSinceLastPromotion', 'YearsWithCurrManager', 'BusinessTravel_Travel_Rarely', |
| | 'BusinessTravel_Travel_Frequently', 'Department_Research & Development', 'Department_Sales', |
| | 'EducationField_Life Sciences', 'EducationField_Medical', 'EducationField_Marketing', |
| | 'EducationField_Other', 'EducationField_Technical Degree', 'Gender_Male', 'JobRole_Research Scientist', |
| | 'JobRole_Sales Executive', 'JobRole_Laboratory Technician', 'JobRole_Manufacturing Director', |
| | 'JobRole_Healthcare Representative', 'JobRole_Manager', 'JobRole_Sales Representative', |
| | 'JobRole_Research Director', 'MaritalStatus_Married', 'MaritalStatus_Single', 'OverTime_Yes'] |
| | |
| | def predict_survival(self, input_data): |
| | df = pd.DataFrame([input_data], columns=self.features) |
| | survival_function = self.model.predict_survival_function(df) |
| | return survival_function.T |
| | |
| | # Load the model and make a prediction |
| | model = HRAttritionModel('cox_model.pkl') |
| | sample_input = {'Age': 41, 'DistanceFromHome': 1, 'Education': 2, 'NumCompaniesWorked': 1, 'PercentSalaryHike': 11, |
| | 'TotalWorkingYears': 8, 'TrainingTimesLastYear': 0, 'WorkLifeBalance': 1, 'YearsInCurrentRole': 4, |
| | 'YearsSinceLastPromotion': 0, 'YearsWithCurrManager': 5, 'BusinessTravel_Travel_Rarely': 1, |
| | 'BusinessTravel_Travel_Frequently': 0, 'Department_Research & Development': 0, 'Department_Sales': 1, |
| | 'EducationField_Life Sciences': 1, 'EducationField_Medical': 0, 'EducationField_Marketing': 0, |
| | 'EducationField_Other': 0, 'EducationField_Technical Degree': 0, 'Gender_Male': 1, |
| | 'JobRole_Research Scientist': 0, 'JobRole_Sales Executive': 0, 'JobRole_Laboratory Technician': 0, |
| | 'JobRole_Manufacturing Director': 0, 'JobRole_Healthcare Representative': 0, 'JobRole_Manager': 0, |
| | 'JobRole_Sales Representative': 0, 'JobRole_Research Director': 0, 'MaritalStatus_Married': 0, |
| | 'MaritalStatus_Single': 1, 'OverTime_Yes': 0} |
| | prediction = model.predict_survival(sample_input) |
| | print(prediction) |