How kartikshingde/ml_mini_project works
Project Type and Purpose
• This is a full-stack machine learning web application.
• Purpose: Allow users to input Titanic passenger features via a React frontend, send those to a Flask API, and return survival predictions from a pre-trained Random Forest ML model.
File-Structure Analysis
• Root folder (backend):
• app.py – Flask application exposing /health and /predict endpoints.
• requirements.txt – Python deps (Flask, Flask-CORS, pandas, numpy, scikit-learn, joblib, gunicorn).
• titanic_model.pkl – Serialized Random Forest model.
• titanic_dataset/ – CSVs for training/test (used by train_model.py if present).
• Frontend folder:
• package.json, vite.config.js – Node/Vite config.
• public/, src/ – React components (App.jsx, main.jsx), CSS, assets.
README Insights
• Ports: Frontend on 5173, Backend on 5000.
• ML: Random Forest, 7 features, ~84% accuracy.
• No external databases or messaging queues—model file is the only persistent store.
a. Main Components
1. Browser/Client (React Frontend)
2. API Server (Flask + CORS)
3. Model Loader & Predictor (joblib-loaded .pkl)
4. (Optional) Training Pipeline: train_model.py + titanic_dataset/
5. External Dependencies: scikit-learn, pandas, numpy
b. Relationships & Data Flows
• User enters form data in React → HTTP POST to Flask /predict.
• Flask endpoint receives JSON → Data preprocessing (pandas/numpy) → Pass to Random Forest model → Prediction + probability returned as JSON.
• React reads the JSON response → Updates UI (show prediction, confidence).
• (Health check) React or curl can GET /health → JSON status.
• Training flow (one-time): train_model.py reads CSVs → trains Random Forest → serializes to titanic_model.pkl → backend can load new model on restart.
c. Architectural Patterns & Principles
• Client-Server (separation of concerns).
• RESTful API (health and predict endpoints).
• Single-page application (React + Vite).
• Model serving as a micro-service (monolithic backend but logically separate model component).
• Config-as-code (requirements.txt, package.json, vite.config.js).
d. Key Technologies & Frameworks
• Frontend: React, Vite, pure CSS, JavaScript/JSX.
• Backend: Python Flask, Flask-CORS.
• ML: scikit-learn RandomForestClassifier, joblib serialization.
• Data: pandas, numpy.
• Dev tooling: virtualenv, npm, nodemodules.