End-to-end phishing URL classification project that demonstrates a production-style ML workflow: data ingestion, validation + drift checks, feature preprocessing, model training + experiment tracking, and interactive inference (batch + single) with explainability.
The goal is to classify a URL instance as Phishing or Legitimate using 30 engineered signals commonly found in phishing datasets (e.g., URL length, HTTPS token, SSL state, anchor URL patterns).
- Highlights
- What This Project Does
- How It Works
- Streamlit Demo
- Screenshots
- Dataset
- Project Structure
- Quickstart (Local)
- Configuration
- API (FastAPI)
- Training (Pipeline)
- Inference schema
- Labels
- Data: MongoDB ingestion + schema validation/drift checks
- ML: preprocessing with
KNNImputer, multi-model training, MLflow tracking - Serving: Streamlit UI (
streamlit_app.py) + FastAPI (app.py) - Demo modes: batch prediction (CSV) and single prediction (interactive + SHAP)
- Train a supervised binary classifier on phishing signals and persist deployable artifacts (preprocessor + model).
- Serve predictions in two ways:
- a Streamlit "recruiter demo" UI with batch scoring, single-case scoring, and explainability
- a FastAPI service for CSV-based batch predictions
- Validate incoming data against a schema and generate a drift report to help catch distribution shifts.
At a high level, the training pipeline is implemented in networksecurity/pipeline/training_pipeline.py and orchestrates:
- Data ingestion (
networksecurity/components/data_ingestion.py)- Pulls records from a MongoDB collection (
MONGO_DB_URL) - Writes a feature store CSV and creates train/test splits
- Pulls records from a MongoDB collection (
- Data validation (
networksecurity/components/data_validation.py)- Validates the schema and runs a KS-test drift check
- Writes a drift report YAML to the artifacts directory
- Data transformation (
networksecurity/components/data_transformation.py)- Fits a
KNNImputerpreprocessing pipeline - Saves the fitted preprocessor to
final_model/preprocessor.pkl
- Fits a
- Model training + tracking (
networksecurity/components/model_trainer.py)- Trains multiple classifiers (including
XGBClassifier) with hyperparameter search - Logs metrics to MLflow (and initializes DagsHub MLflow tracking if configured)
- Saves the trained model to
final_model/model.pkl
- Trains multiple classifiers (including
The Streamlit UI (streamlit_app.py) is designed for a clean walkthrough and supports:
- Batch Prediction: upload a CSV with 30 feature columns and download predictions
- Single Prediction + SHAP: score one instance, show confidence, and plot top feature impact (when SHAP is available)
- Performance Dashboard: view core metrics, confusion matrix, and a classification report on reference data
- Architecture + Tech Stack: a narrative tab for explaining the pipeline and tooling
- Sample dataset:
NetworkData/phisingData.csv(includes the target columnResult). - Training expects the same 30 feature columns shown in Inference schema.
- Label handling:
- The raw dataset uses
Resultvalues like-1and1. - During transformation, the pipeline maps
-1to0so the final labels are0(Phishing) and1(Legitimate).
- The raw dataset uses
networksecurity/: pipeline code (ingestion, validation, transformation, training, utilities)streamlit_app.py: recruiter-ready UI (batch + single + explainability + dashboard)app.py: FastAPI service (/train,/predict) and Swagger docsmain.py: run the training pipeline from the CLIdata_schema/schema.yaml: expected columns + typesfinal_model/: saved artifacts used for inference (model.pkl,preprocessor.pkl)assests/: README screenshots and diagrams (folder name matches the repo)
pip install -r requirements.txt
streamlit run streamlit_app.pyIf you don’t have artifacts in final_model/ yet, run training once:
python main.pySet MONGO_DB_URL (used for ingestion/training), for example by creating a local .env file:
MONGO_DB_URL="your-mongodb-connection-string"- Start the API:
python app.py- Open docs at
http://localhost:8000/docs - Training endpoint:
GET /train - Batch prediction endpoint:
POST /predict(CSV upload)
Run the training pipeline directly:
python main.pyArtifacts are saved under final_model/ (e.g., final_model/model.pkl, final_model/preprocessor.pkl).
Expected 30 input feature columns
having_IP_Address, URL_Length, Shortining_Service, having_At_Symbol, double_slash_redirecting, Prefix_Suffix, having_Sub_Domain, SSLfinal_State, Domain_registeration_length, Favicon, port, HTTPS_token, Request_URL, URL_of_Anchor, Links_in_tags, SFH, Submitting_to_email, Abnormal_URL, Redirect, on_mouseover, RightClick, popUpWidnow, Iframe, age_of_domain, DNSRecord, web_traffic, Page_Rank, Google_Index, Links_pointing_to_page, Statistical_report
0-> Phishing1-> Legitimate





