File size: 2,307 Bytes
1571821
 
 
5a5f8e0
 
1571821
 
 
 
 
 
 
 
 
 
5a5f8e0
 
 
 
 
 
 
 
 
 
 
 
1571821
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a5f8e0
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
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()
        plt.rcParams["figure.figsize"] = [10,10]
        sns.heatmap(data_correlation,xticklabels=data_correlation.columns,yticklabels=data_correlation.columns)
        return fig
    if plot_type == "Age Attrition":
        fig = plt.figure()
        positive_attrition_df = data_encoded.loc[data_encoded['Attrition'] == "Yes"]
        plt.hist(positive_attrition_df['Age'], bins=np.arange(0,80,10), alpha=0.8, rwidth=0.9, color='blue')
        plt.xlabel("Age")
        plt.ylabel("Count")
        plt.title("Age vs Attrition")
        return fig
    if plot_type == "Distance Attrition":
        fig = plt.figure()
        positive_attrition_df = data_encoded.loc[data_encoded['Attrition'] == "Yes"]
        plt.hist(positive_attrition_df['DistanceFromHome'], bins=np.arange(0,80,10), alpha=0.8, rwidth=0.9, color='green')
        plt.xlabel("Distance From Home")
        plt.ylabel("Count")
        plt.title("Distance vs Attrition")
        return fig

inputs = [
        gr.Dropdown(["Find Data Correlation", "Age Attrition", "Distance 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()