nhvrm1998/Explainable-AI-Income-Prediction
0
1import gradio as gr2from model_utils import predict_income3 4# Prediction Function5def predict(6 age,7 fnlwgt,8 education_num,9 capital_gain,10 capital_loss,11 hours_per_week,12 workclass,13 education,14 marital_status,15 occupation,16 relationship,17 race,18 sex,19 native_country20):21 22 user_input = {23 "age": age,24 "fnlwgt": fnlwgt,25 "education_num": education_num,26 "capital_gain": capital_gain,27 "capital_loss": capital_loss,28 "hours_per_week": hours_per_week,29 "workclass": workclass,30 "education": education,31 "marital_status": marital_status,32 "occupation": occupation,33 "relationship": relationship,34 "race": race,35 "sex": sex,36 "native_country": native_country37 }38 39 prediction, confidence = predict_income(user_input)40 41 return (42 f"### Prediction : {prediction}\n\n"43 f"### Confidence : {confidence:.2f}%"44 )45 46 47with gr.Blocks(title="Explainable AI Income Prediction") as demo:48 49 gr.Markdown("# ๐ค Explainable AI Income Prediction")50 51 gr.Markdown("""52Predict whether an individual's annual income is **greater than $50K**.53 54### Model Used55- Random Forest56 57### Explainable AI58- SHAP59- LIME60""")61 62 with gr.Row():63 64 age = gr.Slider(17,90,value=30,label="Age")65 66 fnlwgt = gr.Number(value=150000,label="Final Weight")67 68 education_num = gr.Slider(1,16,value=10,label="Education Number")69 70 with gr.Row():71 72 capital_gain = gr.Number(value=0,label="Capital Gain")73 74 capital_loss = gr.Number(value=0,label="Capital Loss")75 76 hours_per_week = gr.Slider(1,99,value=40,label="Hours Per Week")77 78 with gr.Row():79 80 workclass = gr.Dropdown(81 [82 "Private",83 "Self-emp-not-inc",84 "Self-emp-inc",85 "Federal-gov",86 "Local-gov",87 "State-gov",88 "Without-pay",89 "Never-worked"90 ],91 value="Private",92 label="Workclass"93 )94 95 education = gr.Dropdown(96 [97 "Bachelors",98 "HS-grad",99 "Masters",100 "Some-college",101 "Assoc-voc",102 "Assoc-acdm",103 "Doctorate"104 ],105 value="Bachelors",106 label="Education"107 )108 109 with gr.Row():110 111 marital_status = gr.Textbox(label="Marital Status")112 113 occupation = gr.Textbox(label="Occupation")114 115 with gr.Row():116 117 relationship = gr.Textbox(label="Relationship")118 119 race = gr.Dropdown(120 [121 "White",122 "Black",123 "Asian-Pac-Islander",124 "Other"125 ],126 value="White",127 label="Race"128 )129 130 with gr.Row():131 132 sex = gr.Radio(133 ["Male","Female"],134 value="Male",135 label="Gender"136 )137 138 native_country = gr.Textbox(label="Native Country")139 140 predict_btn = gr.Button("๐ Predict Income")141 142 output = gr.Markdown()143 144 predict_btn.click(145 fn=predict,146 inputs=[147 age,148 fnlwgt,149 education_num,150 capital_gain,151 capital_loss,152 hours_per_week,153 workclass,154 education,155 marital_status,156 occupation,157 relationship,158 race,159 sex,160 native_country161 ],162 outputs=output163 )164 165 gr.Markdown("---")166 167 168gr.Markdown("""169---170## ๐ About this Project171 172This project demonstrates how Explainable Artificial Intelligence (XAI) improves the transparency of machine learning predictions.173 174### Model175Random Forest Classifier176 177### Explainability178โข SHAP179โข LIME180 181### Dataset182Adult Census Income Dataset183 184Developed by **Neha Jhakra**185""")186demo.launch()