Spaces:
Runtime error
Runtime error
import gradio as gr | |
import pandas as pd | |
from sklearn.preprocessing import LabelEncoder | |
from sklearn.feature_selection import mutual_info_classif | |
from sklearn.feature_selection import chi2 | |
from sklearn.linear_model import LinearRegression | |
import numpy as np | |
def update(array_value): | |
df = pd.read_csv('emp_experience_data.csv') | |
pd.options.display.max_columns = 25 | |
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]) | |
data_selected = data_encoded[['EmployeeExperience', 'HealthBenefitsSatisfaction', 'SalarySatisfaction', 'Designation', 'HealthConscious', | |
'EmployeeFeedbackSentiments', 'Education', 'Gender', 'HoursOfTrainingAttendedLastYear', 'InternalJobMovement', 'Attrition']] | |
validation_data = data_selected[100:198] | |
validation_input_data = validation_data.drop(['Attrition'], axis=1) | |
validation_target_data = validation_data[['Attrition']] | |
reg = LinearRegression().fit(validation_input_data, validation_target_data) | |
# In future pass data through array_value parameter | |
if array_value == "2,2,1,3,1,2,0,1,40,1": | |
prediction_value = reg.predict(np.array([[2,2,1,3,1,2,0,1,40,1]])) | |
return f"Prediction : {prediction_value}!" | |
if array_value == "0,0,0,3,0,2,0,1,2,1": | |
prediction_value = reg.predict(np.array([[0,0,0,3,0,2,0,1,2,1]])) | |
return f"Prediction : {prediction_value}!" | |
with gr.Blocks() as demo: | |
gr.Markdown("*** Employee Experience Prediction ***") | |
gr.Markdown("[EmployeeExperience, HealthBenefitsSatisfaction, SalarySatisfaction, Designation, HealthConscious, EmployeeFeedbackSentiments, Education, Gender, HoursOfTrainingAttendedLastYear, InternalJobMovement, Attrition]") | |
with gr.Row(): | |
inp = gr.Dropdown(["2,2,1,3,1,2,0,1,40,1", "0,0,0,3,0,2,0,1,2,1"], label="Prediction Scenario:") | |
out = gr.Textbox() | |
btn = gr.Button("Run") | |
btn.click(fn=update, inputs=inp, outputs=out) | |
demo.launch() |