image_output_1.png
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df = pd.read_csv('../input/hr-analytics-job-change-of-data-scientists/aug_train.csv')

df = df.drop('enrollee_id', axis=1)

fig= plt.figure(figsize=(25, 16))
i = 1

for val in df.columns:
    if val not in ["city", "city_development_index", "training_hours", "target"]:
        fig.add_subplot(4, 3, i, frameon=True, )
        plt.xticks(rotation=45)
        ax = sns.countplot(x=val, data=df,fill=True, edgecolor = sns.color_palette("pastel"))
        i+=1

plt.subplots_adjust(top = 2, bottom=0.2, hspace=0.3)

le = {}
df = df.fillna(0)
for val in df.columns:
    if val not in ['city_development_index', 'training_hours', 'target']:
        le[val] = label_encoding(val)

fig = plt.figure(figsize=(10, 10))
fig.add_subplot()
ax = sns.heatmap(df.corr(), linewidths=.5, square=True, annot=True)
plt.show()

test = pd.read_csv('../input/hr-analytics-job-change-of-data-scientists/aug_test.csv')
enrollee_id = pd.DataFrame(data={'enrollee_id': test['enrollee_id']})
test = test.drop('enrollee_id', axis=1)
test['gender'] = test['gender'].fillna('Other')
test['enrolled_university'] = test['enrolled_university'].fillna('no_enrollment')
test['education_level'] = test['education_level'].fillna('Graduate')
test['major_discipline'] = test['major_discipline'].fillna('STEM')
test['experience'] = test['experience'].fillna('>20')
test['company_size'] = test['company_size'].fillna('50-99')
test['company_type'] = test['company_type'].fillna('Pvt Ltd')
test['last_new_job'] = test['last_new_job'].fillna('1')
test = test.fillna(0)
for val in test.columns:
    if val not in ['city_development_index', 'training_hours', 'target']:
        test[val] = le[val].transform(test[val])

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis
from sklearn.metrics import confusion_matrix, accuracy_score
clf = LinearDiscriminantAnalysis()
clf.fit(df.iloc[:, :-1], df.iloc[:, -1])
y_pred = clf.predict(test)
submission = pd.DataFrame(data={'Enrollee_id': enrollee_id['enrollee_id'], 'target': y_pred})

sns.countplot(data=submission, x='target')