Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,38 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import numpy as np
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import joblib
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
-
ensemble = joblib.load('ensemble_model.joblib')
|
| 8 |
-
|
| 9 |
-
# Load your data
|
| 10 |
df = pd.read_csv('City_Employee_Payroll__Current__20240915.csv', low_memory=False)
|
|
|
|
| 11 |
|
| 12 |
def predict_total_pay(gender, job_title, ethnicity):
|
| 13 |
-
#
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def gradio_predict(gender, ethnicity, job_title):
|
| 17 |
predicted_pay = predict_total_pay(gender, job_title, ethnicity)
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import numpy as np
|
| 3 |
+
from sklearn.ensemble import VotingRegressor
|
| 4 |
import gradio as gr
|
| 5 |
import joblib
|
| 6 |
|
| 7 |
+
# Load your data and trained model
|
|
|
|
|
|
|
|
|
|
| 8 |
df = pd.read_csv('City_Employee_Payroll__Current__20240915.csv', low_memory=False)
|
| 9 |
+
ensemble = joblib.load('ensemble_model.joblib')
|
| 10 |
|
| 11 |
def predict_total_pay(gender, job_title, ethnicity):
|
| 12 |
+
# Create a sample input DataFrame
|
| 13 |
+
sample = pd.DataFrame({
|
| 14 |
+
'GENDER': [gender],
|
| 15 |
+
'JOB_TITLE': [job_title],
|
| 16 |
+
'ETHNICITY': [ethnicity],
|
| 17 |
+
})
|
| 18 |
+
|
| 19 |
+
# Fill in other required features (you may need to adjust this based on your model's requirements)
|
| 20 |
+
sample['EMPLOYMENT_TYPE'] = df['EMPLOYMENT_TYPE'].mode().iloc[0]
|
| 21 |
+
sample['JOB_STATUS'] = df['JOB_STATUS'].mode().iloc[0]
|
| 22 |
+
sample['MOU'] = df['MOU'].mode().iloc[0]
|
| 23 |
+
sample['DEPARTMENT_NO'] = df['DEPARTMENT_NO'].mode().iloc[0]
|
| 24 |
+
sample['PAY_YEAR'] = df['PAY_YEAR'].max()
|
| 25 |
+
sample['REGULAR_PAY'] = df['REGULAR_PAY'].mean()
|
| 26 |
+
sample['OVERTIME_PAY'] = df['OVERTIME_PAY'].mean()
|
| 27 |
+
sample['ALL_OTHER_PAY'] = df['ALL_OTHER_PAY'].mean()
|
| 28 |
+
|
| 29 |
+
# Calculate derived features
|
| 30 |
+
sample['PAY_RATIO'] = sample['REGULAR_PAY'] / (sample['OVERTIME_PAY'] + sample['ALL_OTHER_PAY'] + 1)
|
| 31 |
+
sample['TOTAL_NON_REGULAR_PAY'] = sample['OVERTIME_PAY'] + sample['ALL_OTHER_PAY']
|
| 32 |
+
|
| 33 |
+
# Make prediction
|
| 34 |
+
prediction = ensemble.predict(sample)[0]
|
| 35 |
+
return prediction
|
| 36 |
|
| 37 |
def gradio_predict(gender, ethnicity, job_title):
|
| 38 |
predicted_pay = predict_total_pay(gender, job_title, ethnicity)
|