Spaces:
No application file
No application file
# -*- coding: utf-8 -*- | |
"""Employee Future .ipynb | |
Automatically generated by Colaboratory. | |
Original file is located at | |
https://colab.research.google.com/drive/1qrkFNfcXzUi3JoqFT-2P_Ilcs5PmKA3A | |
""" | |
!pip install xgboost | |
!pip install scikit-learn | |
import pandas as pd | |
from sklearn.compose import ColumnTransformer | |
from sklearn.pipeline import Pipeline | |
from sklearn.preprocessing import OneHotEncoder, StandardScaler | |
from xgboost import XGBClassifier | |
X_train = pd.read_csv('/content/drive/MyDrive/229/Lab07/Employee.csv') | |
X_train | |
X_train['JoiningYear'].unique() | |
y_train = X_train.pop("LeaveOrNot") | |
# Names of numerical features | |
num_col = X_train.select_dtypes(include=['int64', 'float64']).columns | |
# Names of categorical features | |
cat_col = X_train.select_dtypes(include=['object', 'bool']).columns | |
#find tpe of column | |
print(num_col) | |
print(cat_col) | |
preprocessor = ColumnTransformer([("scaler", StandardScaler(), num_col), | |
("onehot", OneHotEncoder(sparse=False), cat_col)]) | |
model = Pipeline(steps=[('preprocessor', preprocessor), | |
('classifier', XGBClassifier())]) | |
model.fit(X_train, y_train) | |
import joblib #function save model | |
joblib.dump(model, 'model.joblib') | |
unique_values = {col:X_train[col].unique() for col in cat_col} | |
joblib.dump(unique_values, 'unique_values.joblib') | |
unique_values | |
import joblib | |
import pandas as pd | |
import streamlit as st | |
model = joblib.load('model.joblib') | |
unique_values = joblib.load('unique_values.joblib') | |
unique_Education = unique_values["Education"] | |
unique_JoiningYear = unique_values["JoiningYear"] | |
unique_City = unique_values["City"] | |
unique_PaymentTier = unique_values["PaymentTier"] | |
unique_Age= unique_values["Age"] | |
unique_Gender = unique_values["Gender"] | |
unique_EverBenched = unique_values["EverBenched"] | |
unique_ExperienceInCurrentDomain = unique_values["ExperienceInCurrentDomain"] | |
def main(): | |
st.title("Employee Future Analysis") | |
with st.form("questionaire"): | |
Age = st.slider("Age", min_value=15, max_value=80) | |
Gender = st.selectbox("Gender", unique_Gender) | |
Education = st.selectbox("Education", unique_Education) | |
JoiningYear = st.slider("JoiningYear", min_value=2010, max_value=2020) | |
City = st.selectbox("City", unique_City) | |
PaymentTier = st.slider("PaymentTier (1: HIGHEST , 2: MID LEVEL , 3: LOWEST)", min_value=1, max_value=3) | |
EverBenched = st.selectbox("EverBenched", unique_EverBenched) | |
ExperienceInCurrentDomain = st.slider("ExperienceInCurrentDomain", min_value=0, max_value=7) | |
clicked = st.form_submit_button("Employee Future") | |
if clicked: | |
result=model.predict(pd.DataFrame({"Age": [Age], | |
"Gender": [Gender], | |
"Education": [Education], | |
"JoiningYear": [JoiningYear], | |
"City": [City], | |
"PaymentTier": [PaymentTier], | |
"EverBenched": [EverBenched], | |
"ExperienceInCurrentDomain" : [ExperienceInCurrentDomain]})) | |
result = '0' if result[0] == 0 else '1' | |
st.success('The predicted Heart Disease is {}'.format(result)) | |
if __name__=='__main__': | |
main() |