Sei sulla pagina 1di 5

APPENDIX B

SOURCE CODE
[1] Employee performance

import sys
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn import tree
import mysql.connector
db = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="hrm"
)
cur = db.cursor()
cur.execute("SELECT * FROM USER_LOG")
df= pd.DataFrame(cur.fetchall())
df.columns = cur.column_names
x=df.iloc[:,[3,4,5,6,8,15,19,20,22]].values
y=df.iloc[:,7]
x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=0,test_size=0.2)
scaler=MinMaxScaler()
x_train=scaler.fit_transform(x_train)
x_test=scaler.transform(x_test)
r=tree.DecisionTreeClassifier()
result=r.fit(x,y)
pred=result.predict([[sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[
6],sys.argv[7],sys.argv[8],sys.argv[9]]])
if pred == 0:
print('performance after 90-day meets')
elif pred == 1:
print('provide Performance Improvement Plan')
elif pred == 2:
print('needs improvement')
elif pred == 3:
print('fully meets the performance criteria!')
elif pred == 4:
print('Exceeds in Performance!!')
elif pred == 5:
print('Exceptional Performance!!!')
else:
print('Too early for prediction')
db.close()

[2] Employee salary


import sys
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn import tree
import mysql.connector
db = mysql.connector.connect(
host="localhost", # your host, usually localhost
user="root", # your username
password="", # your password
database="hrm" # name of the data base
)
cur = db.cursor()
cur.execute("SELECT * FROM USER_LOG")
df= pd.DataFrame(cur.fetchall())
df.columns = cur.column_names
x=df.iloc[:,[3,4,5,6,7,8,15,19]].values
y=df.iloc[:,22]
x_train,x_test,y_train,y_test=train_test_split(x,y,random_state=0)
scaler=MinMaxScaler()
x_train=scaler.fit_transform(x_train)
x_test=scaler.transform(x_test)
r=tree.DecisionTreeClassifier()
result=r.fit(x,y)
pred=result.predict([[sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[
6],sys.argv[7],sys.argv[8]]])
print(pred[0],'$')
db.close()

[3] Employee promotion

import sys
import pandas as pd
import mysql.connector
db = mysql.connector.connect(
host="localhost", # your host, usually localhost
user="root", # your username
password="", # your password
database="hrm" # name of the data base
)

mycur=db.cursor()
sal=[]
sal.append(sys.argv[1])
mycur.execute("select prom_id,up_salary from user_log where Employee_Number=%s",
sal)
df= pd.DataFrame(mycur)
a=df.values
if a[0][0]==1:
print('Congratulations!!!')
print('you have been promoted with Salary ',a[0][1],'$')
else:
print('No promotions Available,your salary is ',a[0][1],'$')

[4] Company performance

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import mysql.connector
db = mysql.connector.connect(
host="localhost", # your host, usually localhost
user="root", # your username
password="", # your password
database="hrm" # name of the data base
)
cur = db.cursor()
cur.execute("SELECT * FROM USER_LOG")
df= pd.DataFrame(cur.fetchall())
df.columns = cur.column_names
b=df.groupby('Perf_ScoreID').size()
c=b.values
if np.max(c)==c[0]:
print("Company's Performance is Poor!")
elif np.max(c)==c[1]:
print("Company's Performance is below Average!")
elif np.max(c)==c[2]:
print("Company's Performance is Average!")
elif np.max(c)==c[3]:
print("Company's Performance is Good!")
elif np.max(c)==c[4]:
print("Company's Performance is Excellent!")
elif np.max(c)==c[5]:
print("Company's Performance is Exceptional!!")
else:
print("Company is a Start-Up, needs time!")
cols=['c','lawngreen','gold','silver','indigo','r','hotpink']
activities=['90-day','PIP','needs_improvement','fully_meets','Exceeds','Exceptional','Too-
early']
plt.pie(b,labels=activities,colors=cols,startangle=90,shadow=True,explode=(0,0,0,0,0,0.0
7,0),autopct='%1.2f%%') #explode is used for highlighting slices
plt.title('company performance')
plt.show()

[5] Salary estimates

import pandas as pd
from matplotlib import pyplot as plt
import mysql.connector
db = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="hrm"
)
cur = db.cursor()
cur.execute("SELECT * FROM USER_LOG")
df1= pd.DataFrame(cur.fetchall())
df1.columns = cur.column_names
a=['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']
b=list()
g=['Accountant I','Administrative Assistant','Shared Services Manager','Sr.
Accountant','President & CEO','CIO','Database Administrator','IT Director','IT Manager -
DB','IT Manager - Infra','IT Manager - Support','IT Support','Network Engineer','Sr.
DBA','Sr. Network Engineer','Director of Operations','Production Manager','Production
Technician I','Production Technician II','Area Sales Manager','Director of Sales','Sales
Manager','Software Engineer','Software Engineering Manager','BI Director','Senior BI
Developer','BI Developer','Data Architect']
for i in range(1,len(a)+1):
sep=df1[df1.pos_id==i]
s=sep.up_salary.sum()
c=sep.up_salary.count()
avg=s//c
b.append(avg)
bar=plt.bar(a,b,width=0.5,color='c')
plt.legend()
plt.xlabel('Position ID')
plt.ylabel('Pay-Scale in US $')
plt.title('PayScale')
plt.show()
res=df1.up_salary.values
up_sal=[]
up_sal.append(int(max(res)))
down_sal=[]

[6] Performance prediction

import sys
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
import sklearn
from sklearn.ensemble import RandomForestClassifier
from sklearn import tree
import mysql.connector
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
db = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="hrm"
cur = db.cursor()
cur.execute("SELECT * FROM USER_LOG")
df= pd.DataFrame(cur.fetchall())
df.columns = cur.column_names
x = df.iloc[:, [3, 4, 5, 6, 8, 11, 15, 19, 20, 21, 22]]
y=df.iloc[:,7]
x_train,x_test,y_train,y_test,=train_test_split(x,y,random_state=0)
scaler=MinMaxScaler()
x_train=scaler.fit_transform(x_train)
x_test=scaler.transform(x_test)
r=tree.DecisionTreeClassifier()
result=r.fit(x,y)
#pred=result.predict([[1,0,1,1,30,1450,3317,1,1,0,28500]])#4
pred=result.predict([[sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[
6],sys.argv[7],sys.argv[8],sys.argv[9],sys.argv[10],sys.argv[11]]])
if pred == 0:
print('performance after 90-day meets')
elif pred == 1:
print('provide Performance Improvement Plan')
elif pred == 2:
print('needs improvement')
elif pred == 3:
print('fully meets the performance criteria!')
elif pred == 4:
print('Exceeds in Performance!!')
elif pred == 5:
print('Exceptional Performance!!!')

Potrebbero piacerti anche