|
| 1 | +import streamlit as st |
| 2 | +import joblib |
| 3 | +import pandas as pd |
| 4 | + |
| 5 | +# Load the model |
| 6 | +model = joblib.load('model.pkl') |
| 7 | + |
| 8 | +# Define the feature columns used in the model |
| 9 | +features = ['Hobby', 'OpenSource', 'Country', 'Student', 'Employment', 'FormalEducation', |
| 10 | + 'UndergradMajor', 'CompanySize', 'DevType', 'YearsCoding', 'YearsCodingProf'] |
| 11 | + |
| 12 | +st.title('Job Satisfaction Prediction') |
| 13 | + |
| 14 | +# Create a form for user input |
| 15 | +with st.form(key='prediction_form'): |
| 16 | + Hobby = st.selectbox('Hobby:', ['Yes', 'No']) |
| 17 | + OpenSource = st.selectbox('Open Source:', ['Yes', 'No']) |
| 18 | + Country = st.selectbox('Country:', ['United States', 'India', 'Germany']) |
| 19 | + Student = st.selectbox('Student:', ['Yes', 'No']) |
| 20 | + Employment = st.selectbox('Employment:', ['Employed full-time', 'Employed part-time', 'Self-employed', 'Unemployed']) |
| 21 | + FormalEducation = st.selectbox('Formal Education:', ["Bachelor’s degree (BA, BS, B.Eng., etc.)", |
| 22 | + "Master’s degree (MA, MS, M.Eng., MBA, etc.)", |
| 23 | + "Doctoral degree (PhD)"]) |
| 24 | + UndergradMajor = st.selectbox('Undergrad Major:', ["Computer science, computer engineering, or software engineering", |
| 25 | + "Information technology, networking, or system administration", |
| 26 | + "Other engineering discipline"]) |
| 27 | + CompanySize = st.selectbox('Company Size:', ['Fewer than 10 employees', '10 to 19 employees', '20 to 99 employees', |
| 28 | + '100 to 499 employees', '500 to 999 employees', '1,000 to 4,999 employees']) |
| 29 | + DevType = st.selectbox('Dev Type:', ['Developer, back-end', 'Developer, front-end', 'Developer, full-stack']) |
| 30 | + YearsCoding = st.selectbox('Years Coding:', ['0-2 years', '3-5 years', '6-8 years', '9-11 years']) |
| 31 | + YearsCodingProf = st.selectbox('Years Coding Professionally:', ['0-2 years', '3-5 years', '6-8 years', '9-11 years']) |
| 32 | + |
| 33 | + submit_button = st.form_submit_button(label='Get Prediction') |
| 34 | + |
| 35 | +if submit_button: |
| 36 | + # Collect user input |
| 37 | + input_data = { |
| 38 | + 'Hobby': Hobby, |
| 39 | + 'OpenSource': OpenSource, |
| 40 | + 'Country': Country, |
| 41 | + 'Student': Student, |
| 42 | + 'Employment': Employment, |
| 43 | + 'FormalEducation': FormalEducation, |
| 44 | + 'UndergradMajor': UndergradMajor, |
| 45 | + 'CompanySize': CompanySize, |
| 46 | + 'DevType': DevType, |
| 47 | + 'YearsCoding': YearsCoding, |
| 48 | + 'YearsCodingProf': YearsCodingProf |
| 49 | + } |
| 50 | + |
| 51 | + # Convert user input to DataFrame |
| 52 | + input_df = pd.DataFrame([input_data]) |
| 53 | + |
| 54 | + # Ensure the input has the same columns as the training data |
| 55 | + input_df = input_df[features] |
| 56 | + |
| 57 | + # Make prediction |
| 58 | + prediction = model.predict(input_df) |
| 59 | + |
| 60 | + # Display the prediction |
| 61 | + st.write(f'Predicted Job Satisfaction: {prediction[0]}') |
0 commit comments