Skip to content

Latest commit

 

History

History
114 lines (85 loc) · 3.99 KB

File metadata and controls

114 lines (85 loc) · 3.99 KB

Model Integration & Dynamic Insights System

Overview

Your Aadhaar Analytics Platform now features a complete ML pipeline with dynamic, AI-generated insights and suggestions using the Gemini API.

How It Works

1. Model Training & Persistence

  • Train a Random Forest model on your Aadhaar dataset
  • Model automatically saves as aadhaar_model.pkl
  • Reusable across sessions without retraining

2. Dynamic Predictions

  • Loads the .pkl model file
  • Generates predictions on your data
  • Computes statistical summaries (total, mean, max, min, by state)

3. AI-Generated Insights

  • Sends prediction data to Gemini API
  • Generates professional policy insights with:
    • Finding: What the data reveals
    • Impact: Operational implications
    • Recommendation: Actionable next steps

4. AI-Generated Suggestions

  • Takes the generated insight as input
  • Uses Gemini API to create 3-5 specific, actionable suggestions
  • Tailored to UIDAI operations and policy

Workflow

1. Upload Dataset → 2. Train Model → 3. Generate Predictions → 4. Ask Questions → 5. Get AI Insights + Suggestions

Step-by-Step Usage

Step 1: Train the Model

  1. Go to Predictive Model page
  2. Click "Train Prediction Model"
  3. Model trains and saves as aadhaar_model.pkl
  4. View R² score and MAE metrics

Step 2: Generate Predictions

  1. Click "Generate Predictions"
  2. View predicted activity statistics
  3. See sample predictions in table

Step 3: Ask Questions

  1. Go to Insight Chat page
  2. Type your question (e.g., "What are the predicted trends?")
  3. Choose:
    • Get Insight: AI-generated insight only
    • Get Insight + Suggestions: Insight + actionable suggestions

File Structure

model_utils.py

  • run_model_pipeline(df) - Train model and save as .pkl
  • load_model() - Load trained model from .pkl
  • make_predictions(df) - Generate predictions using model
  • get_prediction_summary(df, predictions) - Compute statistics

gemini_helper.py

  • classify_intent(question) - Check if question is Aadhaar-related
  • generate_insight_from_predictions(data, question) - Generate insight from predictions
  • generate_suggestions_from_insight(insight) - Generate actionable suggestions

chat_engine.py

  • respond_to_query(query, df) - Main query handler with dynamic insights
  • get_dynamic_suggestions(query, df) - Get both insight + suggestions

insights.py

  • generate_insights(df) - Basic statistical insights
  • generate_prediction_insights(predictions_df) - Prediction-specific insights

API Key Setup

Ensure GEMINI_API_KEY is set:

setx GEMINI_API_KEY "your-api-key-here"

Example Questions

  1. "What are the predicted activity trends for high-population states?"
  2. "Which regions will require more resources based on predictions?"
  3. "What demographic patterns do the predictions reveal?"
  4. "How should UIDAI allocate infrastructure based on forecasts?"

Key Features

Persistent Model - Train once, use many times via .pkl file
Dynamic Insights - AI analyzes predictions in real-time
Actionable Suggestions - Specific recommendations from Gemini
Smart Intent Detection - Filters non-Aadhaar questions
Fallback Handling - Static responses if model not trained
State-wise Analysis - Regional breakdowns in predictions

Error Handling

  • If model not found → Prompts to train model first
  • If Gemini API fails → Returns formatted fallback responses
  • If prediction fails → Uses static insights from data

Benefits

  1. Data-Driven Decisions: Predictions inform resource allocation
  2. AI-Powered Analysis: Gemini interprets complex patterns
  3. Actionable Outputs: Clear recommendations for policy makers
  4. Scalable: Train on new data anytime
  5. Professional Format: Finding/Impact/Recommendation structure