TpsNandhini commited on
Commit
df64dc1
1 Parent(s): cc06346

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.ensemble import RandomForestRegressor
6
+ from sklearn.preprocessing import StandardScaler
7
+ import joblib
8
+
9
+ # Load and preprocess data
10
+ @st.cache_data
11
+ def load_data():
12
+ # Replace this with your actual data loading method
13
+ data = pd.read_csv('employee_performance_data.csv')
14
+ return data
15
+
16
+ # Train model
17
+ @st.cache_resource
18
+ def train_model(data):
19
+ X = data.drop('performance_score', axis=1)
20
+ y = data['performance_score']
21
+
22
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
23
+
24
+ scaler = StandardScaler()
25
+ X_train_scaled = scaler.fit_transform(X_train)
26
+ X_test_scaled = scaler.transform(X_test)
27
+
28
+ model = RandomForestRegressor(n_estimators=100, random_state=42)
29
+ model.fit(X_train_scaled, y_train)
30
+
31
+ return model, scaler
32
+
33
+ # Streamlit app
34
+ def main():
35
+ st.title('Employee Performance Prediction')
36
+
37
+ data = load_data()
38
+ model, scaler = train_model(data)
39
+
40
+ st.sidebar.header('Input Parameters')
41
+
42
+ # Create input fields for user
43
+ age = st.sidebar.slider('Age', 18, 65, 30)
44
+ experience = st.sidebar.slider('Years of Experience', 0, 40, 5)
45
+ training_score = st.sidebar.slider('Training Score', 0.0, 100.0, 75.0)
46
+ project_completion = st.sidebar.slider('Project Completion Rate', 0.0, 100.0, 80.0)
47
+
48
+ # Create a dataframe with user input
49
+ user_input = pd.DataFrame({
50
+ 'age': [age],
51
+ 'experience': [experience],
52
+ 'training_score': [training_score],
53
+ 'project_completion': [project_completion]
54
+ })
55
+
56
+ # Scale the input
57
+ user_input_scaled = scaler.transform(user_input)
58
+
59
+ # Make prediction
60
+ prediction = model.predict(user_input_scaled)
61
+
62
+ st.subheader('Predicted Performance Score')
63
+ st.write(f"{prediction[0]:.2f}")
64
+
65
+ st.subheader('Performance Interpretation')
66
+ if prediction[0] >= 90:
67
+ st.write("Excellent performance!")
68
+ elif prediction[0] >= 75:
69
+ st.write("Good performance")
70
+ elif prediction[0] >= 60:
71
+ st.write("Average performance")
72
+ else:
73
+ st.write("Needs improvement")
74
+
75
+ if __name__ == '__main__':
76
+ main()