Skip to content

Suraj-G-Rao/Network_Security

Repository files navigation

Network Security Threat Detection System

An end-to-end machine learning pipeline for detecting network security threats and phishing attempts with real-time prediction capabilities.

🚀 Features

  • Real-time Threat Detection: Machine learning models for network security threat prediction
  • High-Performance API: FastAPI-based REST API for serving predictions
  • Data Management: MongoDB integration for efficient data storage and retrieval
  • Experiment Tracking: MLflow integration for model lifecycle management
  • Version Control: DagsHub for collaborative ML workflows
  • Robust Architecture: Comprehensive logging and exception handling
  • Production Ready: Scalable deployment configuration

📋 Prerequisites

  • Python 3.8+
  • MongoDB database
  • Git
  • DagsHub account (for version control)

🛠️ Installation

  1. Clone the repository

    git clone https://github.com/Suraj-G-Rao/Network_Security.git
    cd Network_Security
  2. Create and activate virtual environment

    python -m venv venv
    # Windows
    venv\Scripts\activate
    # Linux/Mac
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    # Create a .env file in the root directory
    # Add your MongoDB connection string
    MONGODB_URL_KEY=your_mongodb_connection_string
  5. Install the package

    pip install -e .

🏗️ Project Structure

Network_Security/
├── src/                    # Source code
│   ├── components/         # ML pipeline components
│   ├── constant/          # Configuration constants
│   ├── entity/            # Data entities and configs
│   ├── exception/         # Custom exceptions
│   ├── logging/           # Logging utilities
│   ├── pipeline/          # ML pipelines
│   └── utils/             # Utility functions
├── app.py                 # FastAPI application
├── main.py               # Training pipeline entry point
├── requirements.txt      # Python dependencies
├── setup.py             # Package configuration
├── Network_data/        # Training data
├── final_model/         # Trained models
└── templates/           # HTML templates

🚀 Usage

Training the Model

Run the complete training pipeline:

python main.py

This will execute:

  1. Data Ingestion: Load and prepare training data
  2. Data Validation: Validate data quality and schema
  3. Data Transformation: Preprocess and feature engineer
  4. Model Training: Train the network security model
  5. Model Evaluation: Evaluate model performance

Running the API

Start the FastAPI server:

python app.py

Or using uvicorn directly:

uvicorn app:app --host 0.0.0.0 --port 8000 --reload

The API will be available at http://localhost:8000

API Endpoints

  • GET /: Root endpoint - redirects to prediction interface
  • GET /docs: Interactive API documentation (Swagger UI)
  • POST /predict: Make predictions on network data

Making Predictions

Send a POST request to /predict with network data:

curl -X POST "http://localhost:8000/predict" \
     -H "Content-Type: application/json" \
     -d '{"features": [your_network_features_here]}'

🔧 Configuration

MongoDB Setup

  1. Set up a MongoDB cluster (MongoDB Atlas recommended)
  2. Create a database and collection for network data
  3. Add the connection string to your .env file

DagsHub Integration

  1. Create a DagsHub repository
  2. Configure MLflow tracking:
    import mlflow
    mlflow.set_tracking_uri("your_dagshub_mlflow_uri")

📊 Model Performance

The system includes comprehensive model evaluation with:

  • Accuracy metrics
  • Precision and recall scores
  • Confusion matrix visualization
  • Feature importance analysis

🛡️ Security Features

  • Input Validation: Comprehensive data validation pipeline
  • Error Handling: Robust exception handling throughout
  • Logging: Detailed logging for monitoring and debugging
  • CORS Configuration: Secure cross-origin resource sharing

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

👨‍💻 Author

Suraj G Rao

🙏 Acknowledgments

  • MLflow for experiment tracking
  • FastAPI for high-performance API framework
  • MongoDB for data storage
  • Scikit-learn for machine learning algorithms
  • DagsHub for version control and collaboration

📞 Support

For any queries or support, please reach out via:

About

An end-to-end machine learning pipeline for detecting network security threats and phishing attempts with real-time prediction capabilities. The system leverages FastAPI for high-performance API serving, MongoDB for data management, and MLflow for comprehensive experiment tracking throughout the model lifecycle.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors