Live Application: https://prescribe-ai.streamlit.app/
PrescribeAI is a Streamlit web application that utilizes Association Rule Mining to uncover interesting patterns and relationships within medical prescription data. Inspired by "market basket analysis," this project helps identify which medications are frequently co-prescribed, providing insights into common treatment regimens or potential (though strictly hypothetical in this simulated data) drug interactions.
The application allows users to upload a CSV file containing prescription records and interactively adjust key parameters (Support, Confidence, and Lift) to discover meaningful association rules.
- Data Upload: Easily upload your
fake_prescriptions.csv
(or similar structured CSV) file. - Interactive Parameter Adjustment: Sliders for Minimum Support, Minimum Confidence, and Minimum Lift to dynamically filter and explore association rules.
- Frequent Itemsets Display: Visualize combinations of drugs that frequently appear together.
- Association Rules Display: See the derived rules (e.g.,
{Drug A} -> {Drug B}
) along with their support, confidence, and lift metrics. - Clear Explanations: Understand the meaning and importance of the key metrics.
The application employs the Apriori Algorithm to perform Association Rule Mining:
- Data Preprocessing: The uploaded prescription data is transformed into a transaction-based format, where each prescription is treated as a 'basket' of drugs.
- Frequent Itemset Generation: The Apriori algorithm identifies
frequent itemsets
– combinations of drugs that appear together above a specifiedMinimum Support
threshold. - Association Rule Generation: From these frequent itemsets,
association rules
are generated. These rules are then filtered based onMinimum Confidence
andMinimum Lift
values.
-
Support:
- Indicates how frequently an itemset (a combination of drugs) appears in the entire dataset.
- A higher support means the drug combination is more popular or common.
- Use in App: Configurable via "Minimum Support" slider to focus on common patterns.
-
Confidence:
- Measures how often the rule 'if Antecedent then Consequent' is true. Specifically, it's the probability that the Consequent drugs are prescribed given that the Antecedent drugs were prescribed. (P(B|A)).
- A high confidence suggests a strong likelihood of the Consequent following the Antecedent.
- Use in App: Configurable via "Minimum Confidence" slider to ensure rules are reliable.
-
Lift:
- Evaluates how much more likely the Consequent drugs are prescribed when the Antecedent drugs are also prescribed, compared to the Consequent drugs being prescribed purely by chance (its overall frequency).
- Lift > 1: Indicates a positive correlation; the drugs appear together more often than expected, suggesting a meaningful association. This is what we typically seek.
- Lift = 1: Indicates no correlation (independence).
- Lift < 1: Indicates a negative correlation; the drugs appear together less often than expected.
- Use in App: Configurable via "Minimum Lift" slider to identify truly interesting and non-random relationships.
- Clinical Decision Support: Help doctors identify common co-prescriptions for certain conditions.
- Pharmacovigilance (Drug Safety): Potentially highlight unusual combinations that might warrant further investigation for adverse drug reactions (though this requires medical expertise and real data).
- Inventory Management for Pharmacies: Understand which drugs are frequently dispensed together to optimize stock.
- Drug Development: Inform research into new drug combinations or therapeutic areas.
To run this project locally, follow these steps:
-
Clone the repository (if applicable) or create your project directory:
mkdir PrescribeAI cd PrescribeAI
-
Create your
app.py
file: Save the Streamlit application code (provided previously) asapp.py
inside thePrescribeAI
directory. -
Create your
requirements.txt
file: In the samePrescribeAI
directory, create a file namedrequirements.txt
and add the following content:streamlit pandas mlxtend
-
Install the required libraries: Open your terminal or command prompt, navigate to the
PrescribeAI
directory, and run:pip install -r requirements.txt
-
Generate a
fake_prescriptions.csv
file: You'll need a CSV file to upload. Use the Python script provided earlier to generatefake_prescriptions.csv
and place it in the same directory asapp.py
(or somewhere you can easily browse to). -
Run the Streamlit application: From your terminal in the
PrescribeAI
directory, execute:streamlit run app.py
This will open the application in your default web browser.
The project utilizes a synthetic dataset, prescriptions.csv
, generated using the Faker
library. This dataset simulates medical prescriptions and contains columns such as PatientID
, PrescriptionID
, PrescriptionDate
, Condition
, PatientAge
, PatientGender
, and DrugsPrescribed
(a comma-separated string of medications).
Note: This dataset is purely for demonstration and educational purposes. It does not contain real patient data and should not be used for actual medical analysis or decision-making.
Feel free to explore the app, adjust the parameters, and gain insights into the fascinating world of association rule mining!