Heart Disease Prediction System using SVM (ML)
Heart Disease Prediction: AI-powered web app using SVM to assess heart disease risk. FastAPI backend, Bootstrap UI, MongoDB for history tracking. Predict, store, and analyze with ease!
Demo
About
The problem it solves 1. Predict Heart Disease Risk Easily: This project helps individuals and healthcare professionals assess heart disease risk using machine learning. Users input health details, and the system provides instant predictions. 2. Fast and Reliable Health Insights: Instead of relying on manual analysis, this AI-driven tool quickly evaluates multiple health factors, giving a data-backed prediction on potential heart conditions. 3. User-Friendly Web Interface: The web app offers a simple form-based UI where users can enter their medical data without technical expertise. The results are presented in an easy-to-understand format. 4. Secure Data Storage: The system integrates with MongoDB to store past predictions, allowing users and doctors to track historical data for better decision-making over time. 5. Automated Risk Assessment: Traditional heart disease evaluation involves multiple tests and expert analysis. This tool automates initial risk assessment, helping users decide whether further medical attention is needed. 6. Accessibility and Convenience: Since it runs as a web app, users can access it from any device without needing to install software. This makes heart disease prediction accessible to a wider audience. 7. Support for Early Detection: The system assists in early detection by analyzing key health metrics like blood pressure, cholesterol, heart rate, and other medical factors. 8. Data-Driven Decision Making: By analyzing structured patient data, healthcare providers can make more informed decisions and prioritize high-risk individuals for further screening. 9. Consistent and Objective Analysis: Unlike manual assessments, which may vary by doctor experience, the machine learning model ensures consistency in predictions, reducing human bias. 10. Ideal for Health Awareness Programs: NGOs, health organizations, and researchers can use this tool in awareness campaigns to educate people about heart disease risks and preventive measures. User Interaction and Data Flow 1. User Interaction and Data Flow: This section explains how users interact with the system from input submission to receiving predictions and storing history. 2. Accessing the Application: Users open the web app in a browser and land on a simple form-based interface where they can enter their health-related details. 3. Input Submission: The form requires users to enter medical details such as age, blood pressure, cholesterol, heart rate, chest pain type, and other relevant factors. 4. Submitting Data for Prediction: After filling in the details, users click the Predict button, which sends the input data to the backend API for processing. 5. Backend Processing: The FastAPI server receives the input, validates the data, applies pre-processing techniques, and standardizes it using the trained scaler. 6. Machine Learning Model Execution: The preprocessed data is fed into a trained Support Vector Machine (SVM) model, which analyzes the input and generates a prediction result indicating the risk of heart disease. 7. Displaying Prediction Results: The system returns the prediction result to the frontend, where it is displayed in an easy-to-read format, showing whether the user is at risk or not. 8. Storing the Prediction History: The prediction along with the input data and timestamp is saved in MongoDB, allowing users to track previous results. 9. Viewing Past Predictions: Users can access a history page where all past predictions are displayed in a structured table format, enabling comparison over time. 10. Secure and Efficient Data Handling: The system ensures that sensitive health data is processed securely, with a focus on speed and accuracy to make the tool reliable for real-world use. The project architecture and development process 1. Project Architecture and Development Process: This section outlines the overall structure, core functionalities, and implementation approach for the heart disease prediction system. 2. Solution Overview: The project is a web-based AI system that predicts heart disease risk using a machine learning model (SVM). It consists of a FastAPI backend, a Bootstrap-based frontend, and MongoDB for data storage. 3. Core Functionalities: User input form for health details, machine learning prediction using SVM, result display on UI, database storage for predictions, and history tracking for past results. 4. Backend Implementation: FastAPI handles API requests for prediction, history retrieval, and health checks. The backend loads a pre-trained SVM model and interacts with MongoDB for data storage. 5. Frontend Implementation: HTML and Bootstrap-based interface with index.html for input submission and history.html for viewing past predictions. The UI is designed for ease of use and accessibility. 6. Machine Learning Model: The Support Vector Machine (SVM) model is trained on heart disease data, using StandardScaler for normalization. The trained model is stored as model.pkl for real-time prediction. 7. Database Integration: MongoDB is used to store user inputs and prediction results. PyMongo handles data insertion and retrieval, allowing users to track their health predictions over time. 8. Data Processing: The heart.csv dataset is preprocessed, removing missing values and normalizing features. The cleaned data is used for training the model to ensure accuracy in predictions. 9. Model Training and Evaluation: The SVM model is trained with an RBF kernel and evaluated using accuracy metrics. Performance is tested with real-world input scenarios to ensure reliability. 10. Deployment and Testing: The application is deployed on a server, and thorough testing is conducted to verify correct API functionality, database interactions, and UI performance. Product Integrations 1. Product Integrations: This section highlights the APIs and external services integrated into the project and their specific roles in enhancing functionality. 2. FastAPI: Used as the backend framework to handle API requests, process user inputs, run predictions, and return responses efficiently. 3. Scikit-learn: Provides the machine learning algorithms used in the project, specifically the Support Vector Machine (SVM) model for heart disease prediction. 4. Joblib: Used for serializing and deserializing the trained machine learning model, allowing efficient model loading during API requests. 5. PyMongo: Enables communication between the FastAPI backend and MongoDB, facilitating the storage and retrieval of user input data and prediction history. 6. MongoDB Atlas: Serves as the cloud database solution for securely storing prediction records, making the application scalable and accessible from anywhere. 7. Bootstrap: Provides responsive UI components, enhancing the frontend design and user experience by ensuring a clean and professional layout. 8. Uvicorn: A high-performance ASGI server that runs the FastAPI application, ensuring efficient request handling and API response times. 9. Pandas: Used for data manipulation and preprocessing, allowing efficient handling of user input data before making predictions. 10. NumPy: Supports numerical computations required for feature scaling, dataset transformations, and efficient model execution in real-time. Key differentiators and uniqueness of the project 1. Key Differentiators and Uniqueness of the Project: This section highlights the unique aspects of the heart disease prediction system and how it stands out from similar projects. 2. AI-Powered Prediction: Uses a trained Support Vector Machine (SVM) model for heart disease risk assessment, ensuring reliable and data-driven results. 3. FastAPI for High Performance: Unlike traditional Flask-based applications, FastAPI ensures faster request handling and better scalability for real-time predictions. 4. MongoDB for History Tracking: Unlike many projects that only provide one-time predictions, this system stores past results, allowing users to track their health trends over time. 5. User-Friendly Web Interface: Features a simple and responsive UI built with Bootstrap, making it accessible to non-technical users while ensuring smooth navigation. 6. Secure and Scalable Data Handling: Integrates MongoDB Atlas for secure cloud-based storage, unlike local CSV-based storage seen in many similar projects. 7. Real-Time Data Processing: Implements efficient pre-processing and model execution, ensuring quick response times for predictions with minimal latency. 8. Model Optimization: Uses feature scaling with StandardScaler to improve prediction accuracy, outperforming basic implementations that lack data normalization. 9. Deployment-Ready Architecture: Built with a modular design that allows easy deployment on cloud platforms, making it suitable for real-world healthcare applications. 10. Improved Over Similar Projects: Unlike basic Python scripts that require manual execution, this project offers a fully functional web application with integrated history tracking and API-driven automation. Trade-offs and shortcuts while building 1. Trade-offs and Shortcuts While Building: This section outlines key development decisions, quick fixes, and compromises made, along with areas for future improvements. 2. Model Selection Simplicity: Chose Support Vector Machine (SVM) for ease of implementation and reliable performance, but could explore deep learning models for potentially higher accuracy. 3. FastAPI Over Flask: Opted for FastAPI due to speed and async support but skipped implementing detailed authentication, which is planned for future updates. 4. Limited Feature Engineering: Used basic preprocessing with StandardScaler instead of extensive feature selection techniques, which may improve model performance in future iterations. 5. Basic Frontend Design: Focused on core functionality rather than advanced UI/UX design. Future updates may include interactive visualizations and an improved user experience. 6. MongoDB for Storage: Chose MongoDB for quick integration and NoSQL flexibility, but could optimize queries and indexing for better scalability as user data grows. 7. Minimal Error Handling: Implemented only basic exception handling for API requests. A more robust validation system for user inputs and API responses is planned. 8. Static Model Deployment: The model is loaded as a static file (model.pkl). Future plans include retraining the model periodically with updated medical datasets for improved accuracy. 9. No Multi-Model Comparison: Did not test multiple models due to time constraints. Future updates will evaluate other classifiers like Random Forest, XGBoost, or deep learning approaches. 10. Local Deployment Focus: Currently designed for local and small-scale cloud deployment. Future enhancements will include Kubernetes-based scaling and CI/CD integration for production readiness. Additional Features 1. Additional Features: This section highlights the new functionalities and improvements added during the hackathon to enhance the project’s capabilities. 2. Blockchain Integration: Implemented Reactive Smart Contracts (RSCs) for decentralized health data storage, ensuring tamper-proof medical records and transparent prediction history. 3. Base Deployment: Integrated the Base Layer-2 blockchain for secure and scalable on-chain health record management, improving accessibility and data security. 4. Smart Contract Automation: Developed a smart contract-based alert system to notify users or healthcare providers when a high-risk prediction is detected. 5. Enhanced UI/UX: Improved the Bootstrap-based frontend with real-time feedback on user input and better visualization of prediction results. 6. User Authentication: Added a secure authentication system for managing health records, ensuring only authorized users can access and update their medical data. 7. Performance Optimization: Optimized the FastAPI backend to reduce prediction response time and improve overall application speed. 8. Expanded Machine Learning Models: Introduced additional classification models (Random Forest, XGBoost) to compare performance and improve prediction accuracy. 9. Data Encryption: Implemented AES encryption for sensitive user data before storing it in MongoDB and on-chain, enhancing privacy protection. 10. API Enhancements: Developed RESTful API endpoints for easy integration with other healthcare applications, allowing interoperability within the decentralized ecosystem.