File size: 2,854 Bytes
1571821
 
 
5a5f8e0
 
1571821
 
 
 
 
 
 
 
 
 
5a5f8e0
 
 
 
 
 
 
 
 
786dd64
 
 
 
 
 
 
5a5f8e0
4071a95
1571821
72ac741
1571821
 
 
 
4071a95
1571821
a1538d2
 
 
 
 
 
 
4071a95
 
1571821
 
 
a1538d2
1571821
 
 
 
7062a89
 
 
 
 
 
 
1571821
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn.preprocessing import LabelEncoder
import seaborn as sns

import gradio as gr

plt.switch_backend('Agg')
pd.options.display.max_columns = 25
pd.options.display.max_rows = 300

def outbreak(plot_type):
    df = pd.read_csv('emp_experience_data.csv')
    data_encoded = df.copy(deep=True)
    categorical_column = ['Attrition', 'Gender', 'BusinessTravel', 'Education', 'EmployeeExperience', 'EmployeeFeedbackSentiments', 'Designation',
                            'SalarySatisfaction', 'HealthBenefitsSatisfaction', 'UHGDiscountProgramUsage', 'HealthConscious', 'CareerPathSatisfaction', 'Region']
    label_encoding = LabelEncoder()
    for col in categorical_column:
        data_encoded[col] = label_encoding.fit_transform(data_encoded[col])

    if plot_type == "Find Data Correlation":
        fig = plt.figure()
        data_correlation = data_encoded.corr()
        sns.heatmap(data_correlation, xticklabels = data_correlation.columns, yticklabels = data_correlation.columns)
        return fig
    if plot_type == "Filter Correlation Data":
        fig = plt.figure()
        filtered_df = df[['EmployeeExperience', 'EmployeeFeedbackSentiments', 'Age', 'SalarySatisfaction', 'BusinessTravel', 'HealthBenefitsSatisfaction']]
        correlation_filter_data = filtered_df.corr()
        sns.heatmap(correlation_filter_data, xticklabels = filtered_df.columns, yticklabels = filtered_df.columns)
        return fig
    if plot_type == "Age vs Attrition":
        fig = plt.figure()
        plt.hist(data_encoded['Age'], bins=np.arange(0,80,10), alpha=0.8, rwidth=0.9, color='red')
        plt.xlabel("Age")
        plt.ylabel("Count")
        plt.title("Age vs Attrition")
        return fig
    if plot_type == "Business Travel vs Attrition":
        fig = plt.figure()
        ax = sns.countplot(x="BusinessTravel", hue="Attrition", data=data_encoded)
        for p in ax.patches:
            ax.annotate('{}'.format(p.get_height()), (p.get_x(), p.get_height()+1))
        return fig
    if plot_type == "Employee Experience vs Attrition":
        fig = plt.figure()
        ax = sns.countplot(x="EmployeeExperience", hue="Attrition", data=data_encoded)
        for p in ax.patches:
            ax.annotate('{}'.format(p.get_height()), (p.get_x(), p.get_height()+1))
        return fig

inputs = [
        gr.Dropdown(["Find Data Correlation", "Filter Correlation Data", "Business Travel vs Attrition", "Employee Experience vs Attrition", "Age vs Attrition",], label="Data Correlation and Visualization")
    ]

outputs = gr.Plot()

demo = gr.Interface(
    fn = outbreak,
    inputs = inputs,
    outputs = outputs,
    title="Employee-Experience: Data Correlation and Pattern Visualization",
    allow_flagging=False
)


if __name__ == "__main__":
    demo.launch()