rasmodev commited on
Commit
7c42e3d
1 Parent(s): 4bd969c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +324 -129
app.py CHANGED
@@ -1,135 +1,330 @@
 
1
  import pandas as pd
 
 
2
  import streamlit as st
3
- import numpy as np
4
  import pickle
5
  import catboost
6
  from sklearn.impute import SimpleImputer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- # Load the saved model and unique values:
9
- with open("model_and_key_components.pkl", "rb") as f:
10
- components = pickle.load(f)
11
-
12
- # Extract the individual components
13
- dt_model = components["model"]
14
- unique_values = components["unique_values"]
15
-
16
-
17
- st.image("https://i.ytimg.com/vi/WULwst0vW8g/maxresdefault.jpg")
18
- st.title("Income Prediction App")
19
-
20
- # Sidebar with input field descriptions
21
- st.sidebar.header("Description of the Required Input Fields")
22
- st.sidebar.markdown("**Age**: Enter the age of the individual (e.g., 25, 42, 57).")
23
- st.sidebar.markdown("**Gender**: Select the gender of the individual (e.g., Male, Female).")
24
- st.sidebar.markdown("**Education**: Choose the highest education level of the individual (e.g., Bachelors Degree, High School Graduate, Masters Degree).")
25
- st.sidebar.markdown("**Worker Class**: Select the class of worker for the individual (e.g., Private, Government, Self-employed).")
26
- st.sidebar.markdown("**Marital Status**: Choose the marital status of the individual (e.g., Married, Never married, Divorced).")
27
- st.sidebar.markdown("**Race**: Select the race of the individual (e.g., White, Black, Asian-Pac-Islander).")
28
- st.sidebar.markdown("**Hispanic Origin**: Choose the Hispanic origin of the individual (e.g., Mexican, Puerto Rican, Cuban).")
29
- st.sidebar.markdown("**Full/Part-Time Employment**: Select the employment status as full-time or part-time (e.g., Full-time schedules, Part-time schedules).")
30
- st.sidebar.markdown("**Wage Per Hour**: Enter the wage per hour of the individual (numeric value, e.g., 20.50).")
31
- st.sidebar.markdown("**Weeks Worked Per Year**: Specify the number of weeks the individual worked in a year (numeric value, e.g., 45).")
32
- st.sidebar.markdown("**Industry Code**: Choose the category code of the industry where the individual works (e.g., Category 1, Category 2).")
33
- st.sidebar.markdown("**Major Industry Code**: Select the major industry code of the individual's work (e.g., Industry A, Industry B).")
34
- st.sidebar.markdown("**Occupation Code**: Choose the category code of the occupation of the individual (e.g., Category X, Category Y).")
35
- st.sidebar.markdown("**Major Occupation Code**: Select the major occupation code of the individual (e.g., Occupation 1, Occupation 2).")
36
- st.sidebar.markdown("**Total Employed**: Specify the number of persons worked for the employer (numeric value, e.g., 3, 5).")
37
- st.sidebar.markdown("**Household Stat**: Choose the detailed household and family status of the individual (e.g., Single, Married-civilian spouse present).")
38
- st.sidebar.markdown("**Household Summary**: Select the detailed household summary (e.g., Child under 18 never married, Spouse of householder).")
39
- st.sidebar.markdown("**Veteran Benefits**: Choose whether the individual receives veteran benefits (Yes or No).")
40
- st.sidebar.markdown("**Tax Filer Status**: Select the tax filer status of the individual (e.g., Single, Joint both 65+).")
41
- st.sidebar.markdown("**Gains**: Specify any gains the individual has (numeric value, e.g., 1500.0).")
42
- st.sidebar.markdown("**Losses**: Specify any losses the individual has (numeric value, e.g., 300.0).")
43
- st.sidebar.markdown("**Dividends from Stocks**: Specify any dividends from stocks for the individual (numeric value, e.g., 120.5).")
44
- st.sidebar.markdown("**Citizenship**: Select the citizenship status of the individual (e.g., Native, Foreign Born- Not a citizen of U S).")
45
- st.sidebar.markdown("**Year of Migration**: Enter the year of migration for the individual (numeric value, e.g., 2005).")
46
- st.sidebar.markdown("**Country of Birth**: Choose the individual's birth country (e.g., United-States, Other).")
47
- st.sidebar.markdown("**Importance of Record**: Enter the weight of the instance (numeric value, e.g., 0.9).")
48
-
49
- # Create the input fields in the order of your DataFrame
50
- input_data = {
51
- 'age': 0, # Default values, you can change these as needed
52
- 'gender': unique_values['gender'][0],
53
- 'education': unique_values['education'][0],
54
- 'worker_class': unique_values['worker_class'][0],
55
- 'marital_status': unique_values['marital_status'][0],
56
- 'race': unique_values['race'][0],
57
- 'is_hispanic': unique_values['is_hispanic'][0],
58
- 'employment_commitment': unique_values['employment_commitment'][0],
59
- 'employment_stat': unique_values['employment_stat'][0],
60
- 'wage_per_hour': 0, # Default value
61
- 'working_week_per_year': 0, # Default value
62
- 'industry_code': 0, # Default value
63
- 'industry_code_main': unique_values['industry_code_main'][0],
64
- 'occupation_code': 0, # Default value
65
- 'occupation_code_main': unique_values['occupation_code_main'][0],
66
- 'total_employed': 0, # Default value
67
- 'household_stat': unique_values['household_stat'][0],
68
- 'household_summary': unique_values['household_summary'][0],
69
- 'vet_benefit': 0, # Default value
70
- 'tax_status': unique_values['tax_status'][0],
71
- 'gains': 0, # Default value
72
- 'losses': 0, # Default value
73
- 'stocks_status': 0, # Default value
74
- 'citizenship': unique_values['citizenship'][0],
75
- 'mig_year': 0,
76
- 'country_of_birth_own': 'United-States',
77
- 'importance_of_record': 0.0 # Default value
78
- }
79
-
80
- # Create the input fields
81
- col1, col2, col3 = st.columns(3)
82
-
83
- with col1:
84
- input_data['age'] = st.number_input("Age", min_value=0, key='age')
85
- input_data['gender'] = st.selectbox("Gender", unique_values['gender'], key='gender')
86
- input_data['education'] = st.selectbox("Education", unique_values['education'], key='education')
87
- input_data['worker_class'] = st.selectbox("Class of Worker", unique_values['worker_class'], key='worker_class')
88
- input_data['marital_status'] = st.selectbox("Marital Status", unique_values['marital_status'], key='marital_status')
89
- input_data['race'] = st.selectbox("Race", unique_values['race'], key='race')
90
- input_data['is_hispanic'] = st.selectbox("Hispanic Origin", unique_values['is_hispanic'], key='is_hispanic')
91
- input_data['employment_commitment'] = st.selectbox("Full/Part-Time Employment", unique_values['employment_commitment'], key='employment_commitment')
92
- input_data['employment_stat'] = st.selectbox("Has Own Business Or Is Self Employed", unique_values['employment_stat'], key='employment_stat')
93
- input_data['wage_per_hour'] = st.number_input("Wage Per Hour", min_value=0, key='wage_per_hour')
94
-
95
- with col2:
96
- input_data['working_week_per_year'] = st.number_input("Weeks Worked Per Year", min_value=0, key='working_week_per_year')
97
- input_data['industry_code'] = st.selectbox("Category Code of Industry", unique_values['industry_code'], key='industry_code')
98
- input_data['industry_code_main'] = st.selectbox("Major Industry Code", unique_values['industry_code_main'], key='industry_code_main')
99
- input_data['occupation_code'] = st.selectbox("Category Code of Occupation", unique_values['occupation_code'], key='occupation_code')
100
- input_data['occupation_code_main'] = st.selectbox("Major Occupation Code", unique_values['occupation_code_main'], key='occupation_code_main')
101
- input_data['total_employed'] = st.number_input("Number of Persons Worked for Employer", min_value=0, key='total_employed')
102
- input_data['household_stat'] = st.selectbox("Detailed Household and Family Status", unique_values['household_stat'], key='household_stat')
103
- input_data['household_summary'] = st.selectbox("Detailed Household Summary", unique_values['household_summary'], key='household_summary')
104
- input_data['vet_benefit'] = st.selectbox("Veteran Benefits", unique_values['vet_benefit'], key='vet_benefit')
105
-
106
- with col3:
107
- input_data['tax_status'] = st.selectbox("Tax Filer Status", unique_values['tax_status'], key='tax_status')
108
- input_data['gains'] = st.number_input("Gains", min_value=0, key='gains')
109
- input_data['losses'] = st.number_input("Losses", min_value=0, key='losses')
110
- input_data['stocks_status'] = st.number_input("Dividends from Stocks", min_value=0, key='stocks_status')
111
- input_data['citizenship'] = st.selectbox("Citizenship", unique_values['citizenship'], key='citizenship')
112
- input_data['mig_year'] = st.selectbox("Migration Year", unique_values['mig_year'], key='migration_year')
113
- input_data['country_of_birth_own'] = st.selectbox("Country of Birth", unique_values['country_of_birth_own'], key='country_of_birth_own')
114
- input_data['importance_of_record'] = st.number_input("Importance of Record", min_value=0, key='importance_of_record')
115
-
116
- # Button to make predictions
117
- if st.button("Predict"):
118
- # Transform the input data to a DataFrame for prediction
119
- input_df = pd.DataFrame([input_data])
120
-
121
- # Make predictions
122
- prediction = dt_model.predict(input_df)
123
- prediction_proba = dt_model.predict_proba(input_df)
124
-
125
- # Display prediction result
126
- st.subheader("Prediction")
127
- if prediction[0] == 1:
128
- st.success("This individual is predicted to have an income of over $50K.")
129
- else:
130
- st.error("This individual is predicted to have an income of under $50K")
131
-
132
- # Show prediction probability
133
- st.subheader("Prediction Probability")
134
- st.write(f"The probability of the individual having an income over $50K is: {prediction_proba[0][1]:.2f}")
135
-
 
1
+ import numpy as np
2
  import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
  import streamlit as st
6
+ from streamlit_option_menu import option_menu
7
  import pickle
8
  import catboost
9
  from sklearn.impute import SimpleImputer
10
+ import requests
11
+
12
+ # Custom CSS styles for the top bar
13
+ st.markdown(
14
+ """
15
+ <style>
16
+ .top-bar {
17
+ background-color: #FF4C1B;
18
+ color: white;
19
+ padding: 1rem;
20
+ text-align: center;
21
+ }
22
+ .top-bar a {
23
+ text-decoration: none;
24
+ color: white;
25
+ margin: 10px;
26
+ }
27
+ </style>
28
+ """,
29
+ unsafe_allow_html=True,
30
+ )
31
+
32
+ def home_page():
33
+ # Page title and banner image
34
+ st.title("Income Prediction App")
35
+ st.image("https://i.ytimg.com/vi/WULwst0vW8g/maxresdefault.jpg")
36
+
37
+ st.write("""
38
+ The "Income Prediction Challenge for Azubian" is a data-driven initiative that seeks to address the critical issue of income inequality in developing nations. The project focuses on utilizing machine learning techniques to predict whether an individual's income falls above or below a specific income threshold. By developing a robust predictive model, we aim to contribute to more accurate and cost-effective methods of monitoring key population indicators, such as income levels, between census years. This valuable information will empower policymakers to take more informed actions to mitigate and manage income inequality on a global scale.
39
+ """)
40
+
41
+ # The Problem of Income Inequality
42
+ st.header("The Problem: Income Inequality 💸")
43
+ st.write(
44
+ """
45
+ Income inequality, a pervasive challenge that hinders economic progress and social well-being, demands innovative solutions. The "Income Prediction Challenge for Azubian" tackles this issue head-on, harnessing the power of machine learning to predict individual income levels.
46
+
47
+ **Key Challenges of Income Inequality:** ⚠
48
+
49
+ 1. **Limited Economic Mobility:** 📉
50
+
51
+ Individuals from lower-income households often face barriers to education and professional growth, perpetuating income disparities.
52
+
53
+ 2. **Healthcare Disparities:** 🩺
54
+
55
+ Income inequality often translates into unequal access to quality healthcare, leading to adverse health outcomes for lower-income individuals.
56
+
57
+ 3. **Education Gaps:** 📚
58
+
59
+ Children from low-income households may have limited access to quality education, hindering their future opportunities.
60
+
61
+ 4. **Social Unrest:** 💢
62
+
63
+ Extreme income inequality can fuel social unrest as individuals feel disenfranchised and discouraged.
64
+
65
+ 5. **Economic Impact:** 📉
66
+
67
+ Income inequality impedes economic growth by reducing aggregate demand and creating economic instability.
68
+
69
+ 6. **Policymaking Challenges:** 🧩
70
+
71
+ Policymakers require accurate data and insights to formulate effective strategies for reducing income inequality.
72
+ """)
73
+
74
+
75
+ def solution():
76
+ # Page title
77
+ st.title("Income Prediction Solution")
78
+ st.image("https://d2gg9evh47fn9z.cloudfront.net/1600px_COLOURBOX15103453.jpg")
79
+
80
+ # Solution Overview
81
+ st.header("Solution 💡: Combating Income Inequality with Data-Driven Solutions 📈 ")
82
+ st.write("""
83
+
84
+ The "Income Prediction Challenge for Azubian" utilizes machine learning to predict individual income levels, providing valuable data to policymakers for informed action. This data-driven approach offers several advantages:
85
+
86
+ * **Cost-Effectiveness:** 💰
87
+
88
+ Machine learning models are more cost-effective than traditional census methods.
89
+
90
+ * **Timeliness:** ⏱️
91
+
92
+ Income predictions can be generated frequently, enabling timely interventions.
93
+
94
+ * **Scalability:** 🚀
95
+
96
+ Machine learning models can be scaled to predict incomes for large populations, making them applicable to a wide range of scenarios.
97
+ """)
98
+
99
+ st.header("Objectives: 🎯")
100
+ st.write("""
101
+ 1. **Income Prediction Model:** Develop a robust machine learning model to accurately predict individual income levels.
102
+
103
+ 2. **Economic Inequality Mitigation:** Empower policymakers with data-driven insights to effectively address income inequality.
104
+
105
+ 3. **Cost and Accuracy Improvement:** Enhance income-level monitoring through a cost-effective and accurate method compared to traditional census methods.
106
+
107
+ Join us in tackling income inequality with data-driven solutions!
108
+ """)
109
+
110
+ # Model Description
111
+ st.header("Model Description")
112
+ st.write("""
113
+ **Model Training:**
114
+ *Trained on a dataset of demographic and socioeconomic factors influencing income levels 📊
115
+
116
+ * A [CatBoost Classifier](https://catboost.ai/en/docs/concepts/python-reference_catboostclassifier) supervised learning algorithm used for model development ⚙️
117
+
118
+ **Model Evaluation:**
119
+ * Performance assessed using metrics like accuracy, precision, recall, and F1 score 📈📊
120
+
121
+ * Metrics evaluate the model's ability to correctly classify individual income levels ☑️
122
+ """)
123
+
124
+ # Impact and Benefits
125
+ st.header("Impact and Benefits 📈")
126
+ st.write("""
127
+
128
+ **Empowering Policymakers and Promoting Equitable Growth 📈**
129
+
130
+ By providing accurate and timely insights into income distribution, we can empower policymakers to make informed decisions that:
131
+
132
+ * Enhance understanding of income patterns 📊
133
+
134
+ * Identify areas with high income inequality 📍
135
+
136
+ * Target interventions to address income gaps 🎯
137
+
138
+ * Effectively allocate resources to poverty reduction 💰
139
+
140
+ * Promote economic mobility for individuals from low-income backgrounds ⬆️
141
+
142
+ Overall, this tool has the potential to make a meaningful contribution to the fight against income inequality and promote a more just and equitable society. ⚖️
143
+ """)
144
+
145
+
146
+ def perform_eda():
147
+ st.title("Exploratory Data Analysis")
148
+ st.write("""
149
+ 📊📈 Welcome to the Exploratory Data Analysis for the "Income Prediction" Project! 📈📊
150
+ Dive into the wealth of data and uncover insights about income prediction. Explore the data and understand the factors that contribute to an individual's income level. Let's begin our data-driven journey! 💰🔍
151
+ """)
152
+
153
+ # Show the Power bi dashboard
154
+ power_bi()
155
+
156
+ def power_bi():
157
+ """
158
+ Embeds the Power BI report with specified dimensions and full-screen height.
159
+ """
160
+
161
+ st.subheader("Exploring Income Data")
162
+ st.write("Let's dive deeper into the data to understand income distribution and relationships between variables.")
163
+
164
+ # Embed the Power BI iframe with specified dimensions
165
+ power_bi_html = """
166
+ <iframe title="Sepsis" width="600" height="373.5" src="https://app.powerbi.com/view?r=eyJrIjoiYWI1NTRiNTgtMzc5Yi00MjUzLTk4YzAtYjFlZTk3ZWUwMjEyIiwidCI6IjQ0ODdiNTJmLWYxMTgtNDgzMC1iNDlkLTNjMjk4Y2I3MTA3NSJ9" frameborder="0" allowFullScreen="true"></iframe>
167
+ """
168
+
169
+ st.components.v1.html(power_bi_html)
170
+
171
+ # Ensure full-screen height using CSS
172
+ with st.empty():
173
+ st.write("""
174
+ <style>
175
+ html, body {
176
+ height: 100%;
177
+ margin: 0;
178
+ padding: 0;
179
+ }
180
+
181
+ iframe {
182
+ width: 100%;
183
+ height: 100vh;
184
+ }
185
+ </style>
186
+ """, unsafe_allow_html=True)
187
+
188
+
189
+ def prediction():
190
+
191
+ # Load the saved model and unique values:
192
+ with open("model_and_key_components.pkl", "rb") as f:
193
+ components = pickle.load(f)
194
+
195
+ # Extract the individual components
196
+ dt_model = components["model"]
197
+ unique_values = components["unique_values"]
198
+
199
+
200
+ st.image("https://i.ytimg.com/vi/WULwst0vW8g/maxresdefault.jpg")
201
+ st.title("Income Prediction App")
202
+
203
+ # Sidebar with input field descriptions
204
+ st.sidebar.header("Description of the Required Input Fields")
205
+ st.sidebar.markdown("**Age**: Enter the age of the individual (e.g., 25, 42, 57).")
206
+ st.sidebar.markdown("**Gender**: Select the gender of the individual (e.g., Male, Female).")
207
+ st.sidebar.markdown("**Education**: Choose the highest education level of the individual (e.g., Bachelors Degree, High School Graduate, Masters Degree).")
208
+ st.sidebar.markdown("**Worker Class**: Select the class of worker for the individual (e.g., Private, Government, Self-employed).")
209
+ st.sidebar.markdown("**Marital Status**: Choose the marital status of the individual (e.g., Married, Never married, Divorced).")
210
+ st.sidebar.markdown("**Race**: Select the race of the individual (e.g., White, Black, Asian-Pac-Islander).")
211
+ st.sidebar.markdown("**Hispanic Origin**: Choose the Hispanic origin of the individual (e.g., Mexican, Puerto Rican, Cuban).")
212
+ st.sidebar.markdown("**Full/Part-Time Employment**: Select the employment status as full-time or part-time (e.g., Full-time schedules, Part-time schedules).")
213
+ st.sidebar.markdown("**Wage Per Hour**: Enter the wage per hour of the individual (numeric value, e.g., 20.50).")
214
+ st.sidebar.markdown("**Weeks Worked Per Year**: Specify the number of weeks the individual worked in a year (numeric value, e.g., 45).")
215
+ st.sidebar.markdown("**Industry Code**: Choose the category code of the industry where the individual works (e.g., Category 1, Category 2).")
216
+ st.sidebar.markdown("**Major Industry Code**: Select the major industry code of the individual's work (e.g., Industry A, Industry B).")
217
+ st.sidebar.markdown("**Occupation Code**: Choose the category code of the occupation of the individual (e.g., Category X, Category Y).")
218
+ st.sidebar.markdown("**Major Occupation Code**: Select the major occupation code of the individual (e.g., Occupation 1, Occupation 2).")
219
+ st.sidebar.markdown("**Total Employed**: Specify the number of persons worked for the employer (numeric value, e.g., 3, 5).")
220
+ st.sidebar.markdown("**Household Stat**: Choose the detailed household and family status of the individual (e.g., Single, Married-civilian spouse present).")
221
+ st.sidebar.markdown("**Household Summary**: Select the detailed household summary (e.g., Child under 18 never married, Spouse of householder).")
222
+ st.sidebar.markdown("**Veteran Benefits**: Choose whether the individual receives veteran benefits (Yes or No).")
223
+ st.sidebar.markdown("**Tax Filer Status**: Select the tax filer status of the individual (e.g., Single, Joint both 65+).")
224
+ st.sidebar.markdown("**Gains**: Specify any gains the individual has (numeric value, e.g., 1500.0).")
225
+ st.sidebar.markdown("**Losses**: Specify any losses the individual has (numeric value, e.g., 300.0).")
226
+ st.sidebar.markdown("**Dividends from Stocks**: Specify any dividends from stocks for the individual (numeric value, e.g., 120.5).")
227
+ st.sidebar.markdown("**Citizenship**: Select the citizenship status of the individual (e.g., Native, Foreign Born- Not a citizen of U S).")
228
+ st.sidebar.markdown("**Year of Migration**: Enter the year of migration for the individual (numeric value, e.g., 2005).")
229
+ st.sidebar.markdown("**Country of Birth**: Choose the individual's birth country (e.g., United-States, Other).")
230
+ st.sidebar.markdown("**Importance of Record**: Enter the weight of the instance (numeric value, e.g., 0.9).")
231
+
232
+ # Create the input fields in the order of your DataFrame
233
+ input_data = {
234
+ 'age': 0, # Default values, you can change these as needed
235
+ 'gender': unique_values['gender'][0],
236
+ 'education': unique_values['education'][0],
237
+ 'worker_class': unique_values['worker_class'][0],
238
+ 'marital_status': unique_values['marital_status'][0],
239
+ 'race': unique_values['race'][0],
240
+ 'is_hispanic': unique_values['is_hispanic'][0],
241
+ 'employment_commitment': unique_values['employment_commitment'][0],
242
+ 'employment_stat': unique_values['employment_stat'][0],
243
+ 'wage_per_hour': 0, # Default value
244
+ 'working_week_per_year': 0, # Default value
245
+ 'industry_code': 0, # Default value
246
+ 'industry_code_main': unique_values['industry_code_main'][0],
247
+ 'occupation_code': 0, # Default value
248
+ 'occupation_code_main': unique_values['occupation_code_main'][0],
249
+ 'total_employed': 0, # Default value
250
+ 'household_stat': unique_values['household_stat'][0],
251
+ 'household_summary': unique_values['household_summary'][0],
252
+ 'vet_benefit': 0, # Default value
253
+ 'tax_status': unique_values['tax_status'][0],
254
+ 'gains': 0, # Default value
255
+ 'losses': 0, # Default value
256
+ 'stocks_status': 0, # Default value
257
+ 'citizenship': unique_values['citizenship'][0],
258
+ 'mig_year': 0,
259
+ 'country_of_birth_own': 'United-States',
260
+ 'importance_of_record': 0.0 # Default value
261
+ }
262
+
263
+ # Create the input fields
264
+ col1, col2, col3 = st.columns(3)
265
+
266
+ with col1:
267
+ input_data['age'] = st.number_input("Age", min_value=0, key='age')
268
+ input_data['gender'] = st.selectbox("Gender", unique_values['gender'], key='gender')
269
+ input_data['education'] = st.selectbox("Education", unique_values['education'], key='education')
270
+ input_data['worker_class'] = st.selectbox("Class of Worker", unique_values['worker_class'], key='worker_class')
271
+ input_data['marital_status'] = st.selectbox("Marital Status", unique_values['marital_status'], key='marital_status')
272
+ input_data['race'] = st.selectbox("Race", unique_values['race'], key='race')
273
+ input_data['is_hispanic'] = st.selectbox("Hispanic Origin", unique_values['is_hispanic'], key='is_hispanic')
274
+ input_data['employment_commitment'] = st.selectbox("Full/Part-Time Employment", unique_values['employment_commitment'], key='employment_commitment')
275
+ input_data['employment_stat'] = st.selectbox("Has Own Business Or Is Self Employed", unique_values['employment_stat'], key='employment_stat')
276
+ input_data['wage_per_hour'] = st.number_input("Wage Per Hour", min_value=0, key='wage_per_hour')
277
+
278
+ with col2:
279
+ input_data['working_week_per_year'] = st.number_input("Weeks Worked Per Year", min_value=0, key='working_week_per_year')
280
+ input_data['industry_code'] = st.selectbox("Category Code of Industry", unique_values['industry_code'], key='industry_code')
281
+ input_data['industry_code_main'] = st.selectbox("Major Industry Code", unique_values['industry_code_main'], key='industry_code_main')
282
+ input_data['occupation_code'] = st.selectbox("Category Code of Occupation", unique_values['occupation_code'], key='occupation_code')
283
+ input_data['occupation_code_main'] = st.selectbox("Major Occupation Code", unique_values['occupation_code_main'], key='occupation_code_main')
284
+ input_data['total_employed'] = st.number_input("Number of Persons Worked for Employer", min_value=0, key='total_employed')
285
+ input_data['household_stat'] = st.selectbox("Detailed Household and Family Status", unique_values['household_stat'], key='household_stat')
286
+ input_data['household_summary'] = st.selectbox("Detailed Household Summary", unique_values['household_summary'], key='household_summary')
287
+ input_data['vet_benefit'] = st.selectbox("Veteran Benefits", unique_values['vet_benefit'], key='vet_benefit')
288
+
289
+ with col3:
290
+ input_data['tax_status'] = st.selectbox("Tax Filer Status", unique_values['tax_status'], key='tax_status')
291
+ input_data['gains'] = st.number_input("Gains", min_value=0, key='gains')
292
+ input_data['losses'] = st.number_input("Losses", min_value=0, key='losses')
293
+ input_data['stocks_status'] = st.number_input("Dividends from Stocks", min_value=0, key='stocks_status')
294
+ input_data['citizenship'] = st.selectbox("Citizenship", unique_values['citizenship'], key='citizenship')
295
+ input_data['mig_year'] = st.selectbox("Migration Year", unique_values['mig_year'], key='migration_year')
296
+ input_data['country_of_birth_own'] = st.selectbox("Country of Birth", unique_values['country_of_birth_own'], key='country_of_birth_own')
297
+ input_data['importance_of_record'] = st.number_input("Importance of Record", min_value=0, key='importance_of_record')
298
+
299
+ # Button to make predictions
300
+ if st.button("Predict"):
301
+ # Transform the input data to a DataFrame for prediction
302
+ input_df = pd.DataFrame([input_data])
303
+
304
+ # Make predictions
305
+ prediction = dt_model.predict(input_df)
306
+ prediction_proba = dt_model.predict_proba(input_df)
307
+
308
+ # Display prediction result
309
+ st.subheader("Prediction")
310
+ if prediction[0] == 1:
311
+ st.success("This individual is predicted to have an income of over $50K.")
312
+ else:
313
+ st.error("This individual is predicted to have an income of under $50K")
314
+
315
+ # Show prediction probability
316
+ st.subheader("Prediction Probability")
317
+ st.write(f"The probability of the individual having an income over $50K is: {prediction_proba[0][1]:.2f}")
318
+
319
+
320
+ # Add navigation to the selected page
321
+ selected_page = st.selectbox("Select a page", ["Home", "Solution", "EDA", "Predict Income"])
322
 
323
+ if selected_page == "Home":
324
+ home_page()
325
+ elif selected_page == "Solution":
326
+ solution()
327
+ elif selected_page == "EDA":
328
+ perform_eda()
329
+ else:
330
+ prediction()