<jupyter_start><jupyter_text>HR Analytics on data set from Kaggle using Logistic Regression<jupyter_code>import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
df=pd.read_csv('C:/Users/hp/OneDrive/Documents/GitHub/py/ML/7_logistic_reg/Exercise/HR_comma_sep.csv')
df<jupyter_output><empty_output><jupyter_text>Data Exploratory Analysis<jupyter_code>left=df[df.left==1]
left.shape
retained=df[df.left==0]
retained.shape
df.groupby('left').mean()<jupyter_output><empty_output><jupyter_text>Satisfaction level vs Employee Retention Grap<jupyter_code>plt.scatter(df['satisfaction_level'],df['left'],color='pink',marker='+')
plt.xlabel('satisfaction_level')
plt.ylabel('left')<jupyter_output><empty_output><jupyter_text>Average Montly Hours vs Employee Retention Graph<jupyter_code>plt.scatter(df['average_montly_hours'],df['left'],color='green',marker='*')
plt.xlabel('average_montly_hours')
plt.ylabel('left')<jupyter_output><empty_output><jupyter_text>Promotion in Last 5 years vs Employee Retention Graph<jupyter_code>plt.scatter(df['promotion_last_5years'],df['left'],color='red',marker='*')
plt.xlabel('promotion_last_5years')
plt.ylabel('left')<jupyter_output><empty_output><jupyter_text>Conlcusions: -> Satisfaction_level drastically affect employee retention, if Satisfaction_level is 0.66 then employees tend to not leave, if it is arounf 0.44, they tend to leave.-> average_montly_hours	also affect employee retention, if average_montly_hours is around 199 then employees tend to not leave, if it is around 207 they leave the firm.-> promotion_last_5years also affect empployee retention, if they are likely to be given promotion then they stay.   Impact of employee salaries on retention<jupyter_code>pd.crosstab(df['salary'],df['left']).plot(kind='bar')<jupyter_output><empty_output><jupyter_text>Corelation between department and employee retention<jupyter_code>pd.crosstab(df.Department, df.left).plot(kind='bar')<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code>from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
X=df[['satisfaction_level','average_montly_hours','promotion_last_5years','salary']]
X
y=df['left']
y<jupyter_output><empty_output><jupyter_text>Dealing with text coloumn<jupyter_code>from sklearn.preprocessing import LabelEncoder
le=LabelEncoder()
dfle=df
dfle['salary']=le.fit_transform(dfle['salary'])
dfle
X=dfle[['salary','satisfaction_level','average_montly_hours','promotion_last_5years']].values
X
y=dfle['left'].values
y
from sklearn.preprocessing import OneHotEncoder
from sklearn.compose import ColumnTransformer
ct = ColumnTransformer([('left', OneHotEncoder(), [0])], remainder = 'passthrough')
ct.fit_transform
X=ct.fit_transform(X)
X
X=X[:,1:]
X<jupyter_output><empty_output><jupyter_text>Train and Test Data Set<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3)<jupyter_output><empty_output><jupyter_text>Logistic Regression<jupyter_code>model=LogisticRegression()
model.fit(X,y)
model.predict(X_test)<jupyter_output><empty_output><jupyter_text>Accuracy of the model<jupyter_code>model.score(X_test, y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12349117920148561, 'fraction_numerical': 0.00773754255648406, 'mean_word_length': 11.625, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '400778', 'license': 'MIT', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1132, 'n_words': 195, 'path': 'HR Analytics.ipynb', 'repo_name': 'NIDHI5443/HR-Analytics', 'size': '3231'}