/Employee_attrition.py Secret
Created
November 21, 2020 06:27
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define a dictionary for the target mapping | |
target_map = {'Yes':1, 'No':0} | |
# Use the pandas apply method to numerically encode our attrition target variable | |
attrition["Attrition_numerical"] = attrition["Attrition"].apply(lambda x: target_map[x]) | |
# creating a list of only numerical values | |
numerical = [u'Age', u'DailyRate', u'DistanceFromHome', | |
u'Education', u'EmployeeNumber', u'EnvironmentSatisfaction', | |
u'HourlyRate', u'JobInvolvement', u'JobLevel', u'JobSatisfaction', | |
u'MonthlyIncome', u'MonthlyRate', u'NumCompaniesWorked', | |
u'PercentSalaryHike', u'PerformanceRating', u'RelationshipSatisfaction', | |
u'StockOptionLevel', u'TotalWorkingYears', | |
u'TrainingTimesLastYear', u'WorkLifeBalance', u'YearsAtCompany', | |
u'YearsInCurrentRole', u'YearsSinceLastPromotion',u'YearsWithCurrManager'] | |
data = [ | |
go.Heatmap( | |
z= attrition[numerical].astype(float).corr().values, # Generating the Pearson correlation | |
x=attrition[numerical].columns.values, | |
y=attrition[numerical].columns.values, | |
colorscale='Viridis', | |
reversescale = False, | |
# text = True , | |
opacity = 1.0 | |
) | |
] | |
layout = go.Layout( | |
title='Pearson Correlation of numerical features', | |
xaxis = dict(ticks='', nticks=36), | |
yaxis = dict(ticks='' ), | |
width = 900, height = 700, | |
) | |
fig = go.Figure(data=data, layout=layout) | |
py.iplot(fig, filename='labelled-heatmap') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment