How fugubiao/medical-insurance-forecast works
Project type and purpose
• This is a full‑stack, monolithic Flask web application that hosts a pre‐trained medical‑insurance‑fraud detection model.
• Purpose: allow users to upload or view insurance claim data, run a machine‑learning inference pipeline (outlier treatment, feature selection, PCA, SMOTE, random forest or LightGBM), and display fraud‐risk results with optional tree visualization.
File structure
• Top‑level files:
– app.py: Flask application entry‐point with HTTP routes for inference and visualization
– rantree.py: code to render or traverse random‐forest decision trees
– show_1.py, test.py: auxiliary scripts for demonstration or testing
– requirements.txt: Python dependencies (Flask, scikit‑learn, pandas, numpy, imbalanced‑learn, etc.)
– [csv file]: raw dataset for offline training/analysis
• models/: stores model artifacts (.pkl, .txt) produced by offline training pipeline
• static/: CSS, JS and Bootstrap assets for the browser UI
• templates/: Jinja2 HTML templates for views
Key insights from README
• Offline pipeline steps:
1. 3σ outlier removal
2. Linear regression‑based feature selection
3. PCA dimensionality reduction
4. SMOTE oversampling
5. Cross‑validation
• Models are trained, serialized, and then served by the Flask app.
a. User & Browser UI
b. Frontend assets (static CSS/JS, Bootstrap) + Jinja2 templates
c. Flask Backend
• HTTP Routes / Controllers (in app.py)
• Inference Engine (loads .pkl from models/, calls scikit‑learn predict)
• Tree‑visualization service (rantree.py)
d. Data
• Raw dataset (CSV) – used offline
• Model Artifact Store (models/ folder)
e. Offline ML Pipeline (optional overlay)
• Preprocessing (pandas + custom scripts)
• Training (scikit‑learn, imblearn SMOTE)
• Model serialization
Relationships and interactions
• Browser → HTTP(S) request → Flask controller
• Controller loads model artifact → preprocesses input → inference → render result via template or JSON
• For tree view: controller calls rantree module → renders SVG/HTML snippet → returns to browser
• Offline: CSV data → preprocessing scripts → model trainer → output to models/
Architectural patterns & design principles
• MVC‑like separation:
• Models = serialized ML objects
• Views = Jinja2 templates + static assets
• Controllers = Flask app.py routes
• Single‑process, file‐based persistence (no external DB)
• ML pipeline decoupling: offline training vs. online inference
Technologies, frameworks, libraries
• Python 3.x, Flask, Jinja2
• scikit‑learn, pandas, numpy, imbalanced‑learn (SMOTE), LightGBM (optional)
• Bootstrap 3 & 5 for responsive UI
• Pickle for model serialization
• HTTP request/response
• Prediction requests
• Offline pipeline → model store
• Blue = frontend/UI
• Green = backend app services
• Orange = ML/data pipeline
• Gray = external/filesystem
Don’t overthink – capture every logical component
• User interface (templates, JS)
• Web server & controllers (app.py)
• ML inference modules (model loader, predictor, rantree)
• Data artifacts (CSV, .pkl)
• Offline training pipeline